<?php
$db_pg[dbname] = "keunindya";
$db_pg[user] = "keunindya";
$db_pg[password] = "keunindya";

$db[dbname] = "pajak";
$db[user] = "postgres";
$db[password] = "admin";
$curdir="/xampp/htdocs/keunindya/";
$curdir_gambar="/xampp/htdocs/keunindya/gambar/";
$curdir_news="/var/www/html/simpa/keunindya/news";
$curdir_upload="/xampp/htdocs/keunindya/migrasi_data/";
$NmFileAccount="array_account";
$path_chang_unit="/keunindya1";
#$cusername='gatot';
$var_post.="&inp[tahun]=$inp[tahun]&inp[bulan]=$inp[bulan]&txtcari=$inp[txtcari]&inp[txtcari]=$inp[txtcari]&inp[txtcari_]=$inp[txtcari_]&inp[kode_seleksi]=$inp[kode_seleksi]".var_kirim($inp_par,"mode")."";

	#$tanda_account=",3,2,4,7";
	$tanda_account=cari_k();
	$tanda_lb=laba_rugi_kd();
	$tanda_laba=cari_laba();
$cnospk='A1001';
$ckode_divisi='1';
$jumlah_per_hal = 20;
//$cnospk_pilih='A1001';
$clevel=1;
#$curdir_document="/var/www/html/portal/gambar/knowledge";
$str_alamat_master="/pusat/user.php,/pusat/wilayah.php,/pusat/divisi_propinsi.php,/pusat/sumber_dana.php,/pusat/sd.php,/pusat/material.php,/pusat/komposisi.php,/pusat/detil_komposisi.php,/pusat/frame_komposisi.php,/pusat/owner.php,/pusat/sbu.php,/pusat/satuan.php,/pusat/calendar_kerja.php,/pusat/arp-arb.php,/pusat/propinsi.php,/pusat/kota.php,/pusat/direktorat.php";
$str_alamat_lain="/pusat/tender.php,/pusat/detil-tender.php,/pusat/amandemen.php,/pusat/rab-tender.php,/pusat/sumber-daya.php,/pusat/proyek.php,/pusat/rab-arp.php,/pusat/arp_rab1.php";
$str_alamat_proyek="/proyek/pilih.php,/proyek/bq.php,/proyek/sub-bq.php,/proyek/kode.php,/proyek/rab_tanggal.php,/proyek/pilih_tanggal.php,/proyek/rab.php,/proyek/inp-arp.php,/proyek/arp-arb.php,/proyek/cut-off.php,/proyek/arp-upload.php,/proyek/arp-upload1.php,/proyek/ra-progress.php,/proyek/upload.php,/proyek/ra-biaya.php,/proyek/input-ra-biaya.php,/proyek/ri-progress.php,/proyek/ri-biaya.php,/proyek/input-ri-biaya.php,/proyek/masalah.php,/proyek/foto.php,/proyek/progress.php,/proyek/progress-rari.php,/proyek/progress-biaya-ra.php,/proyek/progress-biaya-ri.php,/proyek/biaya-rari.php,/proyek/proyeksi.php,/proyek/biaya-proyeksi.php,/proyek/rekapitulsi.php,/proyek/kurvas.php,/proyek/laba.php,/proyek/arp-new.php,/proyek/biaya-arp1.php,/proyek/personil.php,/proyek/laba.php,/proyek/detil-proyek";

$sql_log=",user_update as \"USER\",tgl_update as \"TANGGAL\",ip_update as \"IP\",divisi_update as \"DIVISI\",waktu_update as \"WAKTU\"";
$sql_log_cari=",user_update as \"USER\",tgl_update,ip_update,divisi_update,waktu_update";
$ip_update=$REMOTE_ADDR;
$tgl_update=date('Y-m-d');//echo $tgl_update;
$waktu_update=date('H:i:s');
/*
$level[1]="Super Admin";
$level[2]="Administrator";
$level[3]="User Default";
$level[4]="User";
$level[5]="User Proyek";
*/
/*
$peran[1]="Office Engineer";
$peran[2]="Kepala Proyek";
$peran[3]="Ka-Bag/Ka-Wil";
$peran[4]="Ka-Biro";
$peran[5]="Administrator";
$peran[6]="Super Admin";
*/
$level[1]="Not Access";
$level[2]="Read";
$level[3]="Read/Edit";
$level[4]="Read/Write";
$level[5]="All Access";
/*
$permisi["add"]="tolak";
$permisi["edit"]="tolak";
$permisi["delete"]="tolak";
$permisi["access"]="tolak";
$permisi["approve"]="tolak";
$permisi["print"]="tolak";
$permisi["copy"]="tolak";
$permisi["save"]="tolak";
*/
//baca_permisi();
$parameter_sql_cf=" ((account_kode like('%10%') or  account_kode like('%11%')) and (key_lain like('%/KAS/%') or key_lain like('%/B%') or key_lain like('%/DPP/%')))";
$fungsi_pindah="<script>
function loncat(targ,selObj,restore){ //v3.0
 //alert(selObj.options[selObj.selectedIndex].value);
 window.location=selObj.options[selObj.selectedIndex].value;
 // if (restore) selObj.selectedIndex=0;
}
</script>";

//echo cari_k;
function cari_laba(){
	//$sql="select * from tbl_group_account where status='K'";
	$sql="select kode_group_acc from tbl_group_account where status='K' group by kode_group_acc order by kode_group_acc";
	$res=dbresult($sql);//echo $sql."<br>";
	while($r=odbc_fetch_array($res)){
		$kode_acc.=",".$r[kode_group_acc];
	}
	return $kode_acc;
}
function cari_k(){
//	$sql="select * from tbl_group_account where status='K' and kode_group_acc not like '4%' and kode_group_acc not like '5%' and kode_group_acc not like '6%' and kode_group_acc not like '7%' and kode_group_acc not like '8%'";
	//$sql="select * from tbl_group_account where kode_group_acc not like '1%' and kode_group_acc not like '5%' and kode_group_acc not like '6%' and kode_group_acc not like '8%' and kode_group_acc not like '9%'";
	$sql="select kode_group_acc from tbl_group_account where kode_group_acc not like '1%' and kode_group_acc not like '5%' and kode_group_acc not like '6%' and kode_group_acc not like '8%' and kode_group_acc not like '9%' group by kode_group_acc order by kode_group_acc";
	$res=dbresult($sql);//echo $sql."<br>";
	while($r=odbc_fetch_array($res)){
		$kode_acc.=",".$r[kode_group_acc];
	}
	return $kode_acc;
}

function laba_rugi_kd(){
//	$sql="select * from tbl_group_account where (kode_group_acc like '4%' or kode_group_acc like '5%' or kode_group_acc like '6%' or kode_group_acc like '7%' or kode_group_acc like '8%')";
	//$sql="select * from tbl_group_account where (kode_group_acc like '1%' or kode_group_acc like '5%' or kode_group_acc like '6%' or kode_group_acc like '8%' or kode_group_acc like '9%')";
	$sql="select kode_group_acc from tbl_group_account where (kode_group_acc like '1%' or kode_group_acc like '5%' or kode_group_acc like '6%' or kode_group_acc like '8%' or kode_group_acc like '9%') group by kode_group_acc order by kode_group_acc";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res)){
		$kode_acc.=",".$r[kode_group_acc];
	}
	return $kode_acc;
}

function saldo_bulan($account_kode,$bulan,$tahun){
	global $cdivisi_account,$tanda_account;
	$panjang=strlen($account_kode);
	$str_debet_lalu="dsll + ";
	$str_kredit_lalu="ksll + ";
	for($i=1;$i<=$bulan;$i++){
		$str_debet_ini.="dt_$i + ";
		$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	$bulan=trim(str_replace("0","",$bulan));	
	$str_debet=$str_debet_lalu.$str_debet_ini;
	$str_kredit=$str_kredit_lalu.$str_kredit_ini;
	$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($cdivisi_account)." and account_kode like('$account_kode%') group by tahun,substr(account_kode,1,$panjang)";
	$res=dbresult($sql);
	//echo $sql."<br>";


	while($r=odbc_fetch_array($res,0)){;
		$acc=$r[account_kode];
		$kode_awal=substr($acc,0,3);
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];

		$saldo=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);

/*
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];

		$saldo_lalu=$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini];
		//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

		$saldo=($r[jml_debet]-$r[jml_kredit]);
*/
		$arr_temp[$acc]["saldo"]=$saldo==""?0:$saldo;
		$arr_temp[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp[$acc]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
		$arr_temp[$acc]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
		$arr_temp[$acc]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
		$arr_temp[$acc]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
		$arr_temp[$acc]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
		$arr_temp[$acc]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;
	
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;



/*
	if($bulan>0){
		$sql="select dt_$bulan as jml_debet,kt_$bulan as jml_kredit from tbl_summary_account where tahun=$tahun and account_kode='$account_kode'";
		$res=dbresult($sql);
		$r=odbc_fetch_array($res,0);
	}
*/
	return array("debet"=>$r[jml_debet]==''?0:$r[jml_debet],"kredit"=>$r[jml_kredit]==''?0:$r[jml_kredit]);
}

function cari_transaksi_divisi($tahun){
	global $cdivisi_kode;
	$sql="select max(to_number(no_transaksi,'999999999999')) as no_transaksi from tbl_transaksi where true and (data_divisi_kode='$cdivisi_kode' or data_divisi_kode like '$cdivisi_kode.%') and date_part('year',tgl_transaksi)='$tahun'";
//	echo $sql."<br>";
	$rs=dbresult($sql);	
	while($r=odbc_fetch_array($rs)){
		$r[no_transaksi]=$r[no_transaksi]==""?0:$r[no_transaksi];
		return $r[no_transaksi]+1;
	}
}
/*
function cari_bukti_divisi($bulan,$tahun){
	global $cdivisi_kode,$inp;
	$thn_bukti=substr($inp[tahun],2);
	$bln_bukti=$inp[bulan];
	$bln_bukti=strlen($bln_bukti)=="2"?$bln_bukti:"0".$bln_bukti;
	$sq="select max(to_number(no_transaksi,'999999999999')) as no_transaksi from tbl_transaksi where true and (data_divisi_kode='$cdivisi_kode' or data_divisi_kode like '$cdivisi_kode.%') and date_part('month',tgl_transaksi)='$inp[bulan]' and date_part('year',tgl_transaksi)='$inp[tahun]'";
	//echo $sq."<br>";	
	$rs=dbresult($sq);
	$rm=odbc_fetch_array($rs);
	$no_trans=$rm[no_transaksi];
	$no_trans=$no_trans==""?1:$no_trans;

	$sql="select substr(no_bukti,4,5) as no_bukti from tbl_transaksi where true and (data_divisi_kode='$cdivisi_kode' or data_divisi_kode like '$cdivisi_kode.%') and no_transaksi='$no_trans' and tahun='$inp[tahun]'";
	$res=dbresult($sql);
	//echo $sql."<br>";	
	$r=odbc_fetch_array($res);
	$half_bukti=$r[no_bukti]==""?"/KAS/":$r[no_bukti];
	$half_bukti2=$half_bukti.$bln_bukti."/".$thn_bukti;
	//echo	$half_bukti."<br>";
	//echo	$half_bukti2."<br>";
	$sql1="select count(no_bukti) as jml from tbl_transaksi where no_bukti like '%$half_bukti2' and tahun='$inp[tahun]' and data_divisi_kode='$cdivisi_kode'";
	$res1=dbresult($sql1);//echo $sql1."<br>";
	$k=odbc_fetch_array($res1);
	$kd_bukti=strlen($k[jml]);
	if($kd_bukti==1){
		$kode="00".($k[jml]+1).$half_bukti2;
	}else if($kd_bukti==2){
		$kode="0".($k[jml]+1).$half_bukti2;
	}else if($kd_bukti==3){
		$kode=($k[jml]+1).$half_bukti2;
	}else{
		$kode=$k[jml].$half_bukti2;
	}
	return $kode;
}
*/
function cari_bukti_divisi($bulan,$tahun,$sub_nmr_bukti=""){
	global $cdivisi_kode,$inp;
	$sub_nmr_bukti=$sub_nmr_bukti==""?"BNI":$sub_nmr_bukti;
	$thn_bukti=substr($inp[tahun],2);
	$bln_bukti=$inp[bulan];
	$bln_bukti=strlen($bln_bukti)=="2"?$bln_bukti:"0".$bln_bukti;
	$sq="select max(to_number(no_transaksi,'999999999999')) as no_transaksi from tbl_transaksi where true and (data_divisi_kode='$cdivisi_kode' or data_divisi_kode like '$cdivisi_kode.%') and date_part('month',tgl_transaksi)='$inp[bulan]' and date_part('year',tgl_transaksi)='$inp[tahun]'";
	//echo $sq."<br>";	
	$rs=dbresult($sq);
	$rm=odbc_fetch_array($rs);
	$no_trans=$rm[no_transaksi];
	$no_trans=$no_trans==""?1:$no_trans;

	//$tambahe_sql=$sub_nmr_bukti!=""?"and substr(no_bukti,4,3)='$sub_nmr_bukti'":"";
	/*$sql="select substr(no_bukti,4,5) as no_bukti from tbl_transaksi where true and (data_divisi_kode='$cdivisi_kode' or data_divisi_kode like '$cdivisi_kode.%') and no_transaksi='$no_trans' and tahun='$inp[tahun]'	$tambahe_sql";
	$res=dbresult($sql);
	//echo $sql."<br>";	
	$r=odbc_fetch_array($res);
	*/
	//$half_bukti=$r[no_bukti]==""?"/KAS/":$r[no_bukti];
	$half_bukti=$sub_nmr_bukti==""?"/BNI/":"/$sub_nmr_bukti/";	
	$half_bukti2=$half_bukti.$bln_bukti."/".$thn_bukti;
	//echo	$half_bukti."<br>";
	//echo	$half_bukti2."<br>";
	$sql1="select max(substring(no_bukti,1,3)) as no_bukti from tbl_transaksi where no_bukti like '%$half_bukti2' and tahun='$inp[tahun]' and data_divisi_kode='$cdivisi_kode'";
	$res1=dbresult($sql1);
	//echo $sql1."<br>";
	$k=odbc_fetch_array($res1);
	$nmr_kd_bukti=intval($k[no_bukti]);
	$new_nmr_kd_bukti=$nmr_kd_bukti+1;
	$pj_kd_bukti=strlen($new_nmr_kd_bukti);
	//echo $pj_kd_bukti." <-- Dowone, Nomer'e $new_nmr_kd_bukti<br>";
	if($pj_kd_bukti==1){
		$kode="00".($new_nmr_kd_bukti).$half_bukti2;
	}else if($pj_kd_bukti==2){
		$kode="0".($new_nmr_kd_bukti).$half_bukti2;
	}else if($pj_kd_bukti==3){
		$kode=($new_nmr_kd_bukti).$half_bukti2;
	}else{
		$kode=$nmr_kd_bukti.$half_bukti2;
	}
	return $kode;
}
function cari_kode_account($kode_cabang){
	global $cdivisi_kode;
	$sql="select divisi_account from tbl_divisi where divisi_kode='$kode_cabang'";
	$res=dbresult($sql);//echo $sql1."<br>";
	$r=odbc_fetch_array($res);
	$account_kodene=$r[divisi_account];
	return $account_kodene;
}

function nama_bulan($bulan){
	$arr=array ("1" => "Januari","2" => "Februari","3" => "Maret","4" => "April","5" => "Mei","6" => "Juni","7" => "Juli", "8" => "Agustus","9" => "September","01" => "Januari","02" => "Februari","03" => "Maret","04" => "April","05" => "Mei","06" => "Juni","07" => "Juli", "08" => "Agustus","09" => "September","10" => "Oktober","11" => "November","12" => "Desember");
	$hasil=$arr["$bulan"];
	return $hasil;
}

function sql_kode_divisi($divisi_kode=""){
	global $cdivisi_kode;
	$divisi_kode=$divisi_kode==""?$cdivisi_kode:$divisi_kode;
	return " and (data_divisi_kode='$divisi_kode' or data_divisi_kode like '$divisi_kode.%')";
}

function sql_kd_dvs($divisi_kode=""){
	global $cdivisi_kode;
	$divisi_kode=$divisi_kode==""?$cdivisi_kode:$divisi_kode;
	return " and (data_divisi_kode='$divisi_kode')";
}

function sql_divisi_kode($kode_divisine=""){
	global $cdivisi_kode;
	$kode_divisine=$kode_divisine==""?$cdivisi_kode:$kode_divisine;
	if($kode_divisine!="%%%"){
		return " and (data_divisi_kode='$kode_divisine' or data_divisi_kode like '$kode_divisine.%')";
	}else{
		return " and (data_divisi_kode like '%%%')";
	}
}

/*
function sql_divisi_kode(){
	global $cdivisi_kode;
	return " and (data_divisi_kode='$cdivisi_kode')";
}
*/
function sql_account($kode_account){
	$arr_x=split(",",$kode_account);
	while(list($kunci,$nilai)=each($arr_x)){
		$txt.=" account_kode like('%.$nilai.%') or ";
	}
	if($txt<>""){
		$txt=substr($txt,0,strlen($txt)-4);
		$txt=" and ($txt)";
	}
	return $txt;
}

function sql_account2($kode_account){
	$arr_x=split(",",$kode_account);
	while(list($kunci,$nilai)=each($arr_x)){
		$txt.=" account_kode like('%.$nilai.%') or ";
	}
	if($txt<>""){
		$txt=substr($txt,0,strlen($txt)-4);
		$txt=" ($txt)";
	}
	return $txt;
}

function check_dk($r){
	$sql="select * from tbl_cash_flow_new where tanggal='$r[tanggal]' and account_kode='$r[account_kode]' and abs(jumlah)='$r[abs]' and data_divisi_kode='$r[data_divisi_kode]' and no_transaksi='$r[no_transaksi]' order by length(jenis) asc";
	$res=dbresult($sql);
	$i=0;
	while($r=odbc_fetch_array($res)){
		if($i==0){
			$tmp_jenis=$r[jenis];
			if($r[jenis]=="D"){
				$kode="KD";
			}else{
				$kode="DK";
			}
		}else{
			$new_jenis=$r[jenis];
			//echo "$tmp_jenis $new_jenis <br>";
			if($r[jenis]==$kode){
				return $kode;
			}else{
				return "jamal";
			}

		}
		$i=$i+1;
	}
		/*
	echo "$sql <br>";
	print_r($r);
	echo "$r[jenis] <br>";
	if($r[jenis]=="D"){
		$r=odbc_fetch_array($res,1);
		if($r[jenis]=="KD"){
			return "KD";
		}else{
			print_r($r);
			echo "$r[jenis] <br>";
			return "jamal";
		}
	}else{
		$r=odbc_fetch_array($res,1);
		if($r[jenis]=="DK"){
			return "DK";
		}else{
			return "jamal";
		}

	}
*/
}

function generate_cash_flow($parameter_sql_or,$bulan,$tahun){
	global $cdivisi_account;
	global $cdivisi_kode;
	$sql="delete from tbl_cash_flow where date_part('month',tanggal)=$bulan and date_part('year',tanggal)=$tahun";
	dbresult($sql);
	$parameter_sql_and=str_replace("or","and",$parameter_sql_or);
	$r_sl_bulan=saldo_bulan($account_kode,$bulan,$tahun);
	$sql="select key_lain as no_transaksi from tbl_debet_kredit where date_part('month',periode_posting)=$bulan and date_part('year',periode_posting)=$tahun and ($parameter_sql_or) ".sql_account($cdivisi_account)." group by key_lain";
	echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res,0)){
		$no_transaksi.="key_lain='$r[no_transaksi]' or ";
	}
	if($no_transaksi<>""){
		$no_transaksi=substr($no_transaksi,0,strlen($no_transaksi)-4);
		$sql="insert into tbl_cash_flow select date('$tahun-$bulan-1') as tanggal,account_kode,sum(jumlah) as jumlah,jenis,data_divisi_kode from tbl_debet_kredit where date_part('month',periode_posting)=$bulan and date_part('year',periode_posting)=$tahun and ($no_transaksi) ".sql_account($cdivisi_account)." and data_divisi_kode='".$cdivisi_kode."' group by account_kode,jenis,data_divisi_kode";
		$res=dbresult($sql);
	}	
	//return array("debet"=>$r_debet[jml_debet]==''?0:$r_debet[jml_debet],"kredit"=>$r_kredit[jml_kredit]==''?0:$r_kredit[jml_kredit]);
}

function cari_transaksi($account_kode,$bulan,$tahun){
	$r_sl_bulan=saldo_bulan($account_kode,$bulan,$tahun);
	$sql="select  sum(debet) as jml_debet,sum(kredit) as jml_kredit from qry_transaksi_dk where date_part('month',tgl_transaksi)=$bulan and date_part('year',tgl_transaksi)=$tahun and account_kode='$account_kode'";
	$res=dbresult($sql);
	$r=odbc_fetch_array($res,0);
	$r[jml_debet]=$r[jml_debet]+$r_sl_bulan[debet];
	$r[jml_kredit]=$r[jml_kredit]+$r_sl_bulan[kredit];
	return array("debet"=>$r[jml_debet]==''?0:$r[jml_debet],"kredit"=>$r[jml_kredit]==''?0:$r[jml_kredit]);
}

function generate_transaksi($bulan,$tahun,$kode_tengah,$acc_tambahan=""){
	global $cdivisi_account;
	$tambah_sql_account=$acc_tambahan==""?"":"and account_kode like '$acc_tambahan.%'";
//	$sql="select  sum(jumlah) as jumlah,account_kode,jenis from tbl_debet_kredit where date_part('month',periode_posting)=$bulan and date_part('year',periode_posting)=$tahun ".sql_account($cdivisi_account)." group by account_kode,jenis";
	$sql="select  sum(jumlah) as jumlah,account_kode,jenis from tbl_debet_kredit where date_part('month',periode_posting)=$bulan and date_part('year',periode_posting)=$tahun and key_lain not like '%KAN%' ".sql_account($kode_tengah)." $tambah_sql_account group by account_kode,jenis";
	$res=dbresult($sql);
//	echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$kode=$r[account_kode];
		$jenis=$r[jenis];
		$arr[$kode][$jenis]=$r[jumlah];
	}
	return $arr;
}

function transaksi_b_kan($bulan,$tahun){
	global $cdivisi_account;
	$sql="select  sum(jumlah) as jumlah,account_kode,jenis from tbl_debet_kredit where date_part('month',periode_posting)=$bulan and date_part('year',periode_posting)=$tahun ".sql_account($cdivisi_account)." and key_lain not like '%/KAN/%' group by account_kode,jenis";
	//echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res,0)){
		$kode=$r[account_kode];
		$jenis=$r[jenis];
		$arr[$kode][$jenis]=$r[jumlah];
	}
	return $arr;
}

function transaksi_kan($tahun){
	global $cdivisi_account;
	$sql="select  sum(jumlah) as jumlah,account_kode,jenis from tbl_debet_kredit where date_part('year',periode_posting)='$tahun' ".sql_account($cdivisi_account)." and key_lain like '%/KAN/%' group by account_kode,jenis order by account_kode,jenis";
//	echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res,0)){
		$kode=$r[account_kode];
		$jenis=$r[jenis];
		$arr[$kode][$jenis]=$r[jumlah];
	}
	return $arr;
}

function transaksi_kan_aktiva($tahun){
	global $cdivisi_account;
	$sql="select  sum(jumlah) as jumlah,account_kode,jenis,substr(account_kode,1,1) as pot_kode from tbl_debet_kredit where date_part('year',periode_posting)='$tahun' ".sql_account($cdivisi_account)." and key_lain like '%/KAN/%' and substr(account_kode,1,1)<3 group by account_kode,jenis order by account_kode,jenis";
//	echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res,0)){
		$kode=$r[account_kode];
		$jenis=$r[jenis];
		$arr[$kode][$jenis]=$r[jumlah];
	}
	return $arr;
}

function transaksi_kan_pasiva($tahun){
	global $cdivisi_account;
	$sql="select  sum(jumlah) as jumlah,account_kode,jenis,substr(account_kode,1,1) as pot_kode from tbl_debet_kredit where date_part('year',periode_posting)='$tahun' ".sql_account($cdivisi_account)." and key_lain like '%/KAN/%'  and substr(account_kode,1,1)>3 group by account_kode,jenis order by account_kode,jenis";
//	echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res,0)){
		$kode=$r[account_kode];
		$jenis=$r[jenis];
		$arr[$kode][$jenis]=$r[jumlah];
	}
	return $arr;
}

function baca_waktu(){
$waktu_awal=mktime(date("h"),date("i"),date("s"),date("m"),date("j"),date("Y"));
return $waktu_awal;
}

function proses_data_backup($bulan,$tahun){
	global $parameter_sql_cf;
	global $cdivisi_account;
	$waktu_1=baca_waktu();
	$sql="select * from tbl_account where true ".sql_account($cdivisi_account);
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res)){
		$sql_check="select * from tbl_summary_account where tahun=$tahun and account_kode='$r[account_kode]'";
		$res_check=dbresult($sql_check);
		if(odbc_num_rows($res_check)==0){
			$sql_insert="insert into tbl_summary_account (account_kode,tahun) values ('$r[account_kode]','$tahun')";
			dbresult($sql_insert);
		}
		//for($bulan=1;$bulan<=12;$bulan++){
		$arr_trans=cari_transaksi($r[account_kode],$bulan,$tahun);
		$sql_update="update tbl_summary_account set dt_$bulan='$arr_trans[debet]',kt_$bulan='$arr_trans[kredit]' where account_kode='$r[account_kode]' and tahun='$tahun'";
		dbresult($sql_update);
		//}
	}
	$waktu_2=baca_waktu();
	echo datediff("s",$waktu_1,$waktu_2)." detik <br>";
	//generate_cash_flow($parameter_sql_cf,$bulan,$tahun);
	$waktu_3=baca_waktu();
	echo datediff("s",$waktu_2,$waktu_3)." detik <br>";
	echo datediff("s",$waktu_1,$waktu_3)." detik <br>";
}

function baca_rumus($rumus,$arr_nilai){
/*	echo $rumus." yyyy <br>";
	echo "<pre>";
	print_r($arr_nilai);
	echo "</pre>";
*/	eval ("\$rumus= \"$rumus\";"); 
	return  kalkulator("$rumus");
}

function kalkulator($sum){
	    $sum=str_replace("--","+",$sum);
//		echo $sum." xxxx<br>";
            $check = strtr($sum, "0123456789+-*/()", "                ");
//		echo $check."<br>";
            if ( trim($check) == "" ) {
                        $to_eval="\$evalled=" . $sum . ";";
                        eval($to_eval);
            }else{
                        $evalled = "Perhitungan Salah";
            }
            return $evalled;
}

function arr_summary_cf($bulan,$tahun,$panjang=3){
	$bulan=trim(str_replace("0","",$bulan));	
	$sql="select kode_group_acc,sum(debet) as jml_debet,sum(kredit) as jml_kredit from qry_cf_group where date_part('tanggal',year)=$tahun and date_part('tanggal',month)=$bulan";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res,0)){;
		$saldo=($r[jml_debet]-$r[jml_kredit]);
		$acc=$r[kode_group_acc];
		$arr_temp[$acc]["saldo"]=$saldo==""?0:$saldo;
		$arr_temp[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;

}

function nomor_transaksi($tgl1,$tgl2){
	global $cdivisi_account,$cdivisi_kode;
	$sql="select no_transaksi from tbl_cash_flow_new where true ".sql_account($cdivisi_account)." and  tanggal>='$tgl1' and tanggal<='$tgl2' group by no_transaksi";
	//echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res)){
		$no_trans.="'$r[no_transaksi]',";
//		$arr_temp["$r[jenis]"]=$r[no_trans];
		}
	if($no_trans<>""){
		$no_trans=substr($no_trans,0,strlen($no_trans)-1);
	}
	return $no_trans;
//	return $arr_temp;
}

function saldo_akhir($arr,$tgl1,$tgl2){
	global $cdivisi_account,$cdivisi_kode;
	$nomor_transaksi=" (no_bukti like('%/K%') or no_bukti like('%/B%') or no_bukti like('%/D%') and no_bukti not like ('%/KAN/%')  or ((no_bukti like('%/M%') and no_bukti like('%K/%') and (account_kode like '10%' or account_kode like '11%'))))";
	//$nomor_transaksi="(no_bukti like('%/K%') or no_bukti like('%/B%') or no_bukti like('%/D%') and no_bukti not like ('%/KAN/%'))";
	$sql="select substr(account_kode,1,3) as account_kode,jenis,sum(jumlah) as nilai from qry_transaksi2 where (($nomor_transaksi)) and tgl_transaksi>='$tgl1' and tgl_transaksi<='$tgl2' ".sql_account($cdivisi_account)." group by substr(account_kode,1,3),jenis order by account_kode";
	//echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res)){
		$kode=$r[account_kode];
		$arr_temp[$kode]["$r[jenis]"]=$r[nilai]==""?0:$r[nilai];
		}
//	}
/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
*/
	return $arr_temp;
}

function nilai_input($tgl1,$tgl2,$no_bukti_trans,$no_bukti){
	global $cdivisi_account,$cdivisi_kode;
	$nomor_transaksi=" (no_bukti like('%/K%') or no_bukti like('%/B%') or no_bukti like('%/D%') and no_bukti not like ('%/KAN/%'))";
	//$ganti_kondisi=$no_bukti_trans==""?"":" or (no_transaksi in ($no_bukti_trans) and jenis='K')";
	$ganti_kondisi=$no_bukti_trans==""?"":" or (no_transaksi in ($no_bukti_trans) and no_bukti in ($no_bukti) and jenis='K')";
	$kondisi_maneh=" or no_bukti like '%/MBK/%' and jenis='K'";
	$sql="select sum(jumlah) as jumlah,substr(account_kode,1,3) as account_kode from qry_transaksi2 where (($nomor_transaksi and jenis='K') $ganti_kondisi $kondisi_maneh) and tgl_transaksi>='$tgl1' and tgl_transaksi<='$tgl2' ".sql_account($cdivisi_account)." and (account_kode not like '10%' and account_kode not like '11%') group by substr(account_kode,1,3) order by account_kode";
	//echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res)){
		$kode=$r[account_kode];
		$arr_temp[$kode]=$r[jumlah]==""?0:$r[jumlah];
		}
//	}
/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
*/
	return $arr_temp;
}

function nilai_output($tgl1,$tgl2,$no_bukti_trans2,$no_bukti2){
	global $cdivisi_account,$cdivisi_kode;
	$nomor_transaksi=" (no_bukti like('%/K%') or no_bukti like('%/B%') or no_bukti like('%/D%') and no_bukti not like ('%/KAN/%'))";
	//$ganti_kondisi=$no_bukti_trans==""?"":" or (no_transaksi in ($no_bukti_trans) and jenis='D')";
	$ganti_kondisi=$no_bukti_trans2==""?"":" or (no_transaksi in ($no_bukti_trans2) and no_bukti in ($no_bukti2) and jenis='D')";
	$kondisi_maneh=" or key_lain like '%/MBK/%' and jenis='D'";
	//$nomor_transaksi="(no_bukti like('%/K%') or no_bukti like('%/B%') or no_bukti like('%/D%') or key_lain like('%MB%') and no_bukti not like ('%/KAN/%'))";
	$sql="select sum(jumlah) as jumlah,substr(account_kode,1,3) as account_kode from qry_transaksi2 where (($nomor_transaksi and jenis='D') $ganti_kondisi $kondisi_maneh) and tgl_transaksi>='$tgl1' and tgl_transaksi<='$tgl2' ".sql_account($cdivisi_account)." and (account_kode not like '10%' and account_kode not like '11%') group by substr(account_kode,1,3) order by account_kode";
	//echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res)){
		$kode=$r[account_kode];
		$arr_temp[$kode]=$r[jumlah]==""?0:$r[jumlah];
		}
//	}
/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
*/
	return $arr_temp;
}

function nama_account(){
	global $cdivisi_account,$cdivisi_kode;
	$sql="select * from tbl_master_group_acc order by kode_group_acc";
	//echo $sql."<br>";
	$res=dbresult($sql);
	while($r=odbc_fetch_array($res)){
		$kode=$r[kode_group_acc];
		$arr_temp[$kode]=$r[nama_group_acc];
		}
//	}
/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
*/
	return $arr_temp;
}

function saldo_akhir2($arr,$tgl1,$tgl2){
	global $cdivisi_account,$cdivisi_kode,$nomor_transaksi_cf;
	//if ($nomor_transaksi_cf<>""){
		$arr_kode_dbt=split(",","10,11");
		while(list($key,$arr)=each($arr_kode_dbt)){
			$sql="select sum(jumlah) as nilai,substr(account_kode,1,3) as account_kode,jenis from tbl_debet_kredit where account_kode like '$arr%' ".sql_account($cdivisi_account)." and (key_lain like('%/K%') or key_lain like('%/B%') or key_lain like('%/D%')) and periode_posting>='$tgl1' and periode_posting<='$tgl2' and key_lain not like '%/KAN/%' group by substr(account_kode,1,3),jenis order by account_kode";
			//echo $sql."<br>";
			$res=dbresult($sql);
			while($r=odbc_fetch_array($res)){
				$kode=$r[account_kode];
				$arr_temp[$kode]["$r[jenis]"]=$r[nilai]==""?0:$r[nilai];
				}
			}
	//	}
	return $arr_temp;
}

function arr_summary_kons($bulan,$tahun,$panjang=3){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$str_debet_lalu="dsll + ";
	$str_kredit_lalu="ksll + ";
	for($i=1;$i<=$bulan;$i++){
	$str_debet_ini.="dt_$i + ";
	$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	$bulan=trim(str_replace("0","",$bulan));	
	$str_debet=$str_debet_lalu.$str_debet_ini;
	$str_kredit=$str_kredit_lalu.$str_kredit_ini;
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
	$sql_checkd="select * from tbl_divisi where divisi_kode not like '%.%' and divisi_kode<>'EPC' order by divisi_account";
	$res_checkd=dbresult($sql_checkd);//echo $sql_checkd."<br>";
	while($d=odbc_fetch_array($res_checkd)){
		$divisi_account=$d[divisi_account];
		$divisi_kode=$d[divisi_kode];
		$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($divisi_account)." group by tahun,substr(account_kode,1,$panjang)";
		$res=dbresult($sql);//echo $sql;
		//echo $sql."<br>";
		while($r=odbc_fetch_array($res,0)){
			$acc=$r[account_kode];
			$kode_awal=substr($acc,0,3);
			$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
			$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];
			//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

			$saldo=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
			$arr_temp[$acc][$divisi_kode]["saldo"]=$saldo==""?0:$saldo;
			$arr_temp[$acc][$divisi_kode]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
			$arr_temp[$acc][$divisi_kode]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
			$arr_temp[$acc][$divisi_kode]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
			$arr_temp[$acc][$divisi_kode]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
			$arr_temp[$acc][$divisi_kode]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
			$arr_temp[$acc][$divisi_kode]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
			$arr_temp[$acc][$divisi_kode]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
			$arr_temp[$acc][$divisi_kode]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;

		}
	}
	return $arr_temp;

}

function arr_summ_per_akt_tetap1($bulan,$tahun,$panjang=3){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$str_debet_lalu="dsll + ";
	$str_kredit_lalu="ksll + ";
	for($i=1;$i<=$bulan;$i++){
	$str_debet_ini.="dt_$i + ";
	$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	if($str_debet_ini==""){
		$str_debet_ini="0";
	}
	if($str_kredit_ini==""){
		$str_kredit_ini="0";
	}
	$bulan=trim(str_replace("0","",$bulan));	
	$str_debet=$str_debet_lalu.$str_debet_ini;
	$str_kredit=$str_kredit_lalu.$str_kredit_ini;
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
	$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun='$tahun' ".sql_account($cdivisi_account)." and account_kode like '18%.%' and account_kode like '%.%%%0' group by substr(account_kode,1,$panjang) order by substr(account_kode,1,$panjang)";
	$res=dbresult($sql);//echo $sql;
	//echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$acc=$r[account_kode];
//		$acc=substr($r[account_kode],0,3);
		$kode_awal=$acc;
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];
		//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

		$saldo1=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
		$arr_temp1[$acc]["saldo"]=$saldo1==""?0:$saldo1;
		$arr_temp1[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp1[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp1[$acc]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
		$arr_temp1[$acc]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
		$arr_temp1[$acc]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
		$arr_temp1[$acc]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
		$arr_temp1[$acc]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
		$arr_temp1[$acc]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;
	}
	return $arr_temp1;
}

function arr_summ_per_akt_tetap2($bulan,$tahun,$panjang=3){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$str_debet_lalu="dsll + ";
	$str_kredit_lalu="ksll + ";
	for($i=1;$i<=$bulan;$i++){
	$str_debet_ini.="dt_$i + ";
	$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	if($str_debet_ini==""){
		$str_debet_ini="0";
	}
	if($str_kredit_ini==""){
		$str_kredit_ini="0";
	}
	$bulan=trim(str_replace("0","",$bulan));	
	$str_debet=$str_debet_lalu.$str_debet_ini;
	$str_kredit=$str_kredit_lalu.$str_kredit_ini;

	$sql2="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun='$tahun' ".sql_account($cdivisi_account)." and account_kode like '18%.%' and account_kode not like '%.%%%0' group by substr(account_kode,1,$panjang) order by substr(account_kode,1,$panjang)";
	$res2=dbresult($sql2);//echo $sql;
	//echo $sql2."<br>";
	while($r2=odbc_fetch_array($res2,0)){
		$acc2=$r2[account_kode];
		$kode_awal2=$acc2;
		$saldo_lalu2=strpos($tanda_account,$kode_awal2)>0?$r2[jml_kredit_lalu]-$r2[jml_debet_lalu]:$r2[jml_debet_lalu]-$r2[jml_kredit_lalu];
		$saldo_ini2=strpos($tanda_account,$kode_awal2)>0?$r2[jml_kredit_ini]-$r2[jml_debet_ini]:$r2[jml_debet_ini]-$r2[jml_kredit_ini];
		$saldo2=strpos($tanda_account,$kode_awal2)>0?($r2[jml_kredit]-$r2[jml_debet]):($r2[jml_debet]-$r2[jml_kredit]);
		$arr_temp2[$acc2]["saldo"]=$saldo2==""?0:$saldo2;
		$arr_temp2[$acc2]["debet"]=$r2[jml_debet]==""?0:$r2[jml_debet];
		$arr_temp2[$acc2]["kredit"]=$r2[jml_kredit]==""?0:$r2[jml_kredit];
		$arr_temp2[$acc2]["debet_lalu"]=$r2[jml_debet_lalu]==""?0:$r2[jml_debet_lalu];
		$arr_temp2[$acc2]["kredit_lalu"]=$r2[jml_kredit_lalu]==""?0:$r2[jml_kredit_lalu];;
		$arr_temp2[$acc2]["saldo_lalu"]=$saldo_lalu2==""?0:$saldo_lalu2;
		$arr_temp2[$acc2]["debet_ini"]=$r2[jml_debet_ini]==""?0:$r2[jml_debet_ini];
		$arr_temp2[$acc2]["kredit_ini"]=$r2[jml_kredit_ini]==""?0:$r2[jml_kredit_ini];;
		$arr_temp2[$acc2]["saldo_ini"]=$saldo_ini2==""?0:$saldo_ini2;
	}
/*	$sql3="select account_kode from tbl_account where account_kode like '18%' ".sql_account($cdivisi_account)." group by account_kode order by account_kode";
	$res3=dbresult($sql3);//echo $sql;
	//echo $sql3."<br>";
	while($r3=odbc_fetch_array($res3,0)){
		$acc3=$r3[account_kode];
		$kode_akhir=substr($acc,-1,1);
		$sub_acc3=substr($acc3,0,3);
		$arr_temp[$acc3]["saldo_lalu"]=$arr_temp2[$acc3]["saldo_lalu"];
		$arr_temp[$acc3]["saldo"]=$arr_temp1[$acc3]["saldo"];
		$arr_temp[$acc3]["debet"]=$arr_temp1[$acc3]["debet"]-$arr_temp2[$acc3]["debet"];
		$arr_temp[$acc3]["kredit"]=$arr_temp2[$acc3]["debet"]-$arr_temp2[$acc3]["kredit"];
	}
*/	return $arr_temp2;
}

function arr_sum_acc_18s($bulan,$tahun,$panjang=12){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$str_debet_lalu="dsll + ";
	$str_kredit_lalu="ksll + ";
	for($i=1;$i<=$bulan;$i++){
	$str_debet_ini.="dt_$i + ";
	$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	if($str_debet_ini==""){
		$str_debet_ini="0";
	}
	if($str_kredit_ini==""){
		$str_kredit_ini="0";
	}
	$bulan=trim(str_replace("0","",$bulan));	
	$str_debet=$str_debet_lalu.$str_debet_ini;
	$str_kredit=$str_kredit_lalu.$str_kredit_ini;
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
	$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun='$tahun' ".sql_account($cdivisi_account)." and account_kode like '18%.%' and account_kode like '%.%%%0' group by substr(account_kode,1,$panjang) order by substr(account_kode,1,$panjang)";
	$res=dbresult($sql);//echo $sql;
	//echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$acc=$r[account_kode];
		$kode_awal=substr($acc,0,3);
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];
		//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

		$saldo1=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
		$arr_temp1[$acc]["saldo"]=$saldo1==""?0:$saldo1;
		$arr_temp1[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp1[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp1[$acc]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
		$arr_temp1[$acc]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
		$arr_temp1[$acc]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
		$arr_temp1[$acc]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
		$arr_temp1[$acc]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
		$arr_temp1[$acc]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;
	}
	$sql2="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun='$tahun' ".sql_account($cdivisi_account)." and account_kode like '18%.%' and account_kode not like '%.%%%0' group by substr(account_kode,1,$panjang) order by substr(account_kode,1,$panjang)";
	$res2=dbresult($sql2);//echo $sql;
	//echo $sql2."<br>";
	while($r2=odbc_fetch_array($res2,0)){
		$acc2=$r2[account_kode];
		$kode_awal2=substr($acc2,0,3);
		$saldo_lalu2=strpos($tanda_account,$kode_awal2)>0?$r2[jml_kredit_lalu]-$r2[jml_debet_lalu]:$r2[jml_debet_lalu]-$r2[jml_kredit_lalu];
		$saldo_ini2=strpos($tanda_account,$kode_awal2)>0?$r2[jml_kredit_ini]-$r2[jml_debet_ini]:$r2[jml_debet_ini]-$r2[jml_kredit_ini];
		$saldo2=strpos($tanda_account,$kode_awal2)>0?($r2[jml_kredit]-$r2[jml_debet]):($r2[jml_debet]-$r2[jml_kredit]);
		$arr_temp2[$acc2]["saldo"]=$saldo2==""?0:$saldo2;
		$arr_temp2[$acc2]["debet"]=$r2[jml_debet]==""?0:$r2[jml_debet];
		$arr_temp2[$acc2]["kredit"]=$r2[jml_kredit]==""?0:$r2[jml_kredit];
		$arr_temp2[$acc2]["debet_lalu"]=$r2[jml_debet_lalu]==""?0:$r2[jml_debet_lalu];
		$arr_temp2[$acc2]["kredit_lalu"]=$r2[jml_kredit_lalu]==""?0:$r2[jml_kredit_lalu];;
		$arr_temp2[$acc2]["saldo_lalu"]=$saldo_lalu2==""?0:$saldo_lalu2;
		$arr_temp2[$acc2]["debet_ini"]=$r2[jml_debet_ini]==""?0:$r2[jml_debet_ini];
		$arr_temp2[$acc2]["kredit_ini"]=$r2[jml_kredit_ini]==""?0:$r2[jml_kredit_ini];;
		$arr_temp2[$acc2]["saldo_ini"]=$saldo_ini2==""?0:$saldo_ini2;
	}
	$sql3="select account_kode from tbl_summary_account where account_kode like '18%' ".sql_account($cdivisi_account)." group by account_kode order by account_kode";
	$res3=dbresult($sql3);//echo $sql;
	//echo $sql3."<br>";
	while($r3=odbc_fetch_array($res3,0)){
		$acc3=$r3[account_kode];
		$kode_akhir=substr($acc,-1,1);
		$sub_acc3=substr($acc3,0,3);
		$arr_temp[$acc3]["saldo"]=$arr_temp1[$acc3]["saldo"]==""?0:$arr_temp1[$acc3]["saldo"];
		$arr_temp[$acc3]["debet"]=$arr_temp1[$acc3]["debet"]-$arr_temp2[$acc3]["debet"];
		$arr_temp[$acc3]["kredit"]=$arr_temp2[$acc3]["debet"]-$arr_temp2[$acc3]["kredit"];
	}
/*	echo "<pre>";
	print_r($arr_temp1);
	echo "</pre>";
*/	
	return $arr_temp;

}
/*
function arr_sum_acc_18s_2($bulan1,$bulan2,$tahun,$panjang=12){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$bulan1=$bulan1=="01"?1:$bulan1;
	if($bulan1=="1"){
		$str_debet_lalu="dsll + ";
		$str_kredit_lalu="ksll + ";
	}else{
		$str_debet_lalu="";
		$str_kredit_lalu="";
	}
//	$str_debet_lalu=substr($str_debet_lalu,0,strlen($str_debet_lalu)-4);
//	$str_kredit_lalu=substr($str_kredit_lalu,0,strlen($str_kredit_lalu)-4);
	for($i=$bulan1;$i<=$bulan2;$i++){
		$str_debet_ini.="dt_$i + ";
		$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	$bulan1=trim(str_replace("0","",$bulan1));	
	if($bulan1=="1"){
		$str_debet=$str_debet_lalu.$str_debet_ini;
		$str_kredit=$str_kredit_lalu.$str_kredit_ini;
	}else{
		$str_debet=$str_debet_ini;
		$str_kredit=$str_kredit_ini;
	}
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
	$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun='$tahun' ".sql_account($cdivisi_account)." and account_kode like '18%.%' and account_kode like '%.%%%0' group by substr(account_kode,1,$panjang) order by substr(account_kode,1,$panjang)";
	$res=dbresult($sql);//echo $sql;
	//echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$acc=$r[account_kode];
		$kode_awal=substr($acc,0,3);
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];
		//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

		$saldo1=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
		$arr_temp1[$acc]["saldo"]=$saldo1==""?0:$saldo1;
		$arr_temp1[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp1[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp1[$acc]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
		$arr_temp1[$acc]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
		$arr_temp1[$acc]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
		$arr_temp1[$acc]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
		$arr_temp1[$acc]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
		$arr_temp1[$acc]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;
	}
	$sql2="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun='$tahun' ".sql_account($cdivisi_account)." and account_kode like '18%.%' and account_kode not like '%.%%%0' group by substr(account_kode,1,$panjang) order by substr(account_kode,1,$panjang)";
	$res2=dbresult($sql2);//echo $sql;
	//echo $sql2."<br>";
	while($r2=odbc_fetch_array($res2,0)){
		$acc2=$r2[account_kode];
		$kode_awal2=substr($acc2,0,3);
		$saldo_lalu2=strpos($tanda_account,$kode_awal2)>0?$r2[jml_kredit_lalu]-$r2[jml_debet_lalu]:$r2[jml_debet_lalu]-$r2[jml_kredit_lalu];
		$saldo_ini2=strpos($tanda_account,$kode_awal2)>0?$r2[jml_kredit_ini]-$r2[jml_debet_ini]:$r2[jml_debet_ini]-$r2[jml_kredit_ini];
		$saldo2=strpos($tanda_account,$kode_awal2)>0?($r2[jml_kredit]-$r2[jml_debet]):($r2[jml_debet]-$r2[jml_kredit]);
		$arr_temp2[$acc2]["saldo"]=$saldo2==""?0:$saldo2;
		$arr_temp2[$acc2]["debet"]=$r2[jml_debet]==""?0:$r2[jml_debet];
		$arr_temp2[$acc2]["kredit"]=$r2[jml_kredit]==""?0:$r2[jml_kredit];
		$arr_temp2[$acc2]["debet_lalu"]=$r2[jml_debet_lalu]==""?0:$r2[jml_debet_lalu];
		$arr_temp2[$acc2]["kredit_lalu"]=$r2[jml_kredit_lalu]==""?0:$r2[jml_kredit_lalu];;
		$arr_temp2[$acc2]["saldo_lalu"]=$saldo_lalu2==""?0:$saldo_lalu2;
		$arr_temp2[$acc2]["debet_ini"]=$r2[jml_debet_ini]==""?0:$r2[jml_debet_ini];
		$arr_temp2[$acc2]["kredit_ini"]=$r2[jml_kredit_ini]==""?0:$r2[jml_kredit_ini];;
		$arr_temp2[$acc2]["saldo_ini"]=$saldo_ini2==""?0:$saldo_ini2;
	}
	$sql3="select account_kode from tbl_account where account_kode like '18%' ".sql_account($cdivisi_account)." and tahun='$tahun' group by account_kode order by account_kode";
	$res3=dbresult($sql3);/echo $sql;
	//echo $sql3."<br>";
	while($r3=odbc_fetch_array($res3,0)){
		$acc3=$r3[account_kode];
		$kode_akhir=substr($acc,-1,1);
		$sub_acc3=substr($acc3,0,3);
		$arr_temp[$acc3]["saldo"]=$arr_temp1[$acc3]["saldo"];
		$arr_temp[$acc3]["debet"]=$arr_temp1[$acc3]["debet"]-$arr_temp2[$acc3]["debet"];
		$arr_temp[$acc3]["kredit"]=$arr_temp2[$acc3]["debet"]-$arr_temp2[$acc3]["kredit"];
	}
/*	echo "<pre>";
	print_r($arr_temp1);
	echo "</pre>";
	
	return $arr_temp;
}
*/

function arr_nggawe_halaman($max_record,$arr_baris,$jenis1,$jenis2,$jenis3,$jenis4,$jenis5="tanda_tangan"){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;

	$record=$max_record;
	$posisi_ideal=43;
	$baris_ideal=($record*ceil(count($arr_baris)/$record));
	$jml_hal=$baris_ideal/$record;
	$record=$posisi_ideal;
	$record_min_4=$record-4;
	$record_min_telu=$record-3;
	$record_min_2=$record-2;
	$record_min_1=$record-1;
	$record_min_3=$record-8;
	echo $arr_baris[0][isi];
	$pr_baris=1;
	for($h=0;$h<=$jml_hal;$h++){
		for($ib=1;$ib<=$posisi_ideal;$ib++){
			$print_n=true;	
			if(($ib % $record_min_2==0)or($ib % $record_min_1==0)or($ib % $record_min_3==1)or($ib % $record==0)or($ib % $record_min_telu==0)or($ib % $record_min_4==0)){
				if($ib % $record_min_4==0){
					$jml_chek=3;
					//echo " $ib -- $pr_baris --".$arr_baris[$pr_baris][jenis]."---- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4 and $arr_baris[$pr_baris-5][jenis]==$jenis1){
						for($jb=0;$jb<=$jml_chek+1;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal pinter kok',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif($ib % $record_min_telu==0){
					$jml_chek=3;
					//echo " $ib -- $pr_baris --".$arr_baris[$pr_baris][jenis]."---- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
						for($jb=0;$jb<=$jml_chek+1;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal neng ndi',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif(($ib % $record_min_2==0)){
					$jml_chek=3;
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3 and $arr_baris[$pr_baris+$jml_chek+1][jenis]<>$jenis4){
						for($jb=0;$jb<=$jml_chek;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal ngganteng',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
				//	}
				//}elseif(($ib % $record_min_2==0)){
				//	$jml_chek=3;
					}elseif($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
						for($jb=0;$jb<=$jml_chek;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal 1',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif(($ib % $record_min_3)==1 and $ib!=1){
					$jml_chek=4;
					//echo "xxxxx $ib -- $pr_baris --".$arr_baris[$pr_baris][jenis]."---- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					//echo "xxxxx $ib -- $pr_baris -- $record_min_3 ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis5){
						//echo "masukkkkkkkkkkkkkkk $jenis5";
						for($jb=1;$jb<=9;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal 2',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif(($ib % $record_min_1==0)){
					$jml_chek=2;
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3 and $arr_baris[$pr_baris-1][jenis]<>$jenis1){
						for($jb=0;$jb<=$jml_chek;$jb++){
							//echo $arr_baris[0][isi];
							echo str_replace('jamal','jamal 9',$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}elseif($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2 and $arr_baris[$pr_baris+$jml_chek+1][jenis]==$jenis4){
						for($jb=0;$jb<=$jml_chek;$jb++){
							//echo $arr_baris[0][isi];
							echo str_replace('jamal','jamal 3',$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif(($ib % $record==0)){
					$jml_chek=1;
					//echo " test $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2){
						for($jb=0;$jb<=$jml_chek;$jb++){
							echo str_replace('jamal','jamal 4',$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}elseif($arr_baris[$pr_baris][jenis]==$jenis1){
						for($jb=0;$jb<=$jml_chek;$jb++){
							echo str_replace('jamal','jamal 5',$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
					}
				}

				if($print_n){
					//echo "$ib -- $pr_baris -- ".$arr_baris[$pr_baris][isi];
					//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
					echo $arr_baris[$pr_baris][isi];
					$pr_baris++;
				}
			}else{
				//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
				//echo "$pr_baris --". $arr_baris[$pr_baris][isi];
				echo $arr_baris[$pr_baris][isi];
				$pr_baris++;
			}
			//}
		}
		for($j=$ib;$j<=$max_record;$j++){
			if(($baris_ideal-$pr_baris)>5){
				echo str_replace('jamal',"jamal 6 $pr_baris -- $ib -- $baris_ideal",$arr_baris[-1][isi]);
				$ib++;
			}
		}
		if($pr_baris>=(count($arr_baris)-1)){
			//echo "testtt";
			break;	
		}

	}
	return $arr_baris;
	//echo $arr_baris[$pr_baris][isi];
}

function nggawe_hal_komparatif_konsolidasi($max_record,$arr_baris,$jenis1,$jenis2,$jenis3,$jenis4,$jenis5="tanda_tangan"){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;

	$record=$max_record;
	$posisi_ideal=43;
	$baris_ideal=($record*ceil(count($arr_baris)/$record));
	$jml_hal=$baris_ideal/$record;
	$record=$posisi_ideal;
	$record_min_4=$record-4;
	$record_min_telu=$record-3;
	$record_min_2=$record-2;
	$record_min_1=$record-1;
	$record_min_3=$record-8;
	echo $arr_baris[0][isi];
	$pr_baris=1;
	for($h=0;$h<=$jml_hal;$h++){
		for($ib=1;$ib<=$posisi_ideal;$ib++){
			$print_n=true;	
			if(($ib % $record_min_2==0)or($ib % $record_min_1==0)or($ib % $record_min_3==1)or($ib % $record==0)or($ib % $record_min_telu==0)or($ib % $record_min_4==0)){
				if($ib % $record_min_4==0){
					$jml_chek=3;
					//echo " $ib -- $pr_baris --".$arr_baris[$pr_baris][jenis]."---- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4 and $arr_baris[$pr_baris-5][jenis]==$jenis1){
						for($jb=0;$jb<=$jml_chek+1;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal pinter kok',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif($ib % $record_min_telu==0){
					$jml_chek=3;
					//echo " $ib -- $pr_baris --".$arr_baris[$pr_baris][jenis]."---- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
						for($jb=0;$jb<=$jml_chek+1;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal neng ndi',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif(($ib % $record_min_2==0)){
					$jml_chek=3;
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3 and $arr_baris[$pr_baris+$jml_chek+1][jenis]<>$jenis4){
						for($jb=0;$jb<=$jml_chek;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal ngganteng',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
				//	}
				//}elseif(($ib % $record_min_2==0)){
				//	$jml_chek=3;
					}elseif($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
						for($jb=0;$jb<=$jml_chek;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal 1',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif(($ib % $record_min_3)==1 and $ib!=1){
					$jml_chek=4;
					//echo "xxxxx $ib -- $pr_baris --".$arr_baris[$pr_baris][jenis]."---- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					//echo "xxxxx $ib -- $pr_baris -- $record_min_3 ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis5){
						//echo "masukkkkkkkkkkkkkkk $jenis5";
						for($jb=1;$jb<=9;$jb++){
							//echo $arr_baris[0][isi];
							//echo $arr_baris[-1][isi];
							echo str_replace('jamal','jamal 2',$arr_baris[-1][isi]);
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif(($ib % $record_min_1==0)){
					$jml_chek=2;
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3 and $arr_baris[$pr_baris-1][jenis]<>$jenis1){
						for($jb=0;$jb<=$jml_chek;$jb++){
							//echo $arr_baris[0][isi];
							echo str_replace('jamal','jamal 9',$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}elseif($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2 and $arr_baris[$pr_baris+$jml_chek+1][jenis]==$jenis4){
						for($jb=0;$jb<=$jml_chek;$jb++){
							//echo $arr_baris[0][isi];
							echo str_replace('jamal','jamal 3',$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}
				}elseif(($ib % $record==0)){
					$jml_chek=1;
					//echo " test $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2){
						for($jb=0;$jb<=$jml_chek;$jb++){
							echo str_replace('jamal','jamal 4',$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}elseif($arr_baris[$pr_baris][jenis]==$jenis1){
						for($jb=0;$jb<=$jml_chek;$jb++){
							echo str_replace('jamal','jamal 5',$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
					}
				}

				if($print_n){
					//echo "$ib -- $pr_baris -- ".$arr_baris[$pr_baris][isi];
					//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
					echo $arr_baris[$pr_baris][isi];
					$pr_baris++;
				}
			}else{
				//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
				//echo "$pr_baris --". $arr_baris[$pr_baris][isi];
				echo $arr_baris[$pr_baris][isi];
				$pr_baris++;
			}
			//}
		}
		for($j=$ib;$j<=$max_record;$j++){
			if(($baris_ideal-$pr_baris)>5){
				echo str_replace('jamal',"jamal 6 $pr_baris -- $ib -- $baris_ideal",$arr_baris[-1][isi]);
				$ib++;
			}
		}
		if($pr_baris>=(count($arr_baris)-1)){
			//echo "testtt";
			break;	
		}

	}
	return $arr_baris;
	//echo $arr_baris[$pr_baris][isi];
}

/*
function nggawe_hal_komparatif_konsolidasi($max_record,$arr_baris,$jenis1,$jenis2,$jenis3,$jenis4,$jenis5="tanda_tangan"){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$record=$max_record;
	$baris_ideal=($record*ceil(count($arr_baris)/$record))+10;
	$record_min_2=$record-2;
	$record_min_1=$record-1;
	$record_min_3=$record-5;
	echo $arr_baris[0][isi];
	$pr_baris=1;
	for($ib=1;$ib<=$baris_ideal;$ib++){
		$print_n=true;	
		//if(($ib % 43==0)or($ib % 44==0)){
		//echo str_replace('xxx','yyy',$arr_baris[0][isi]);
		//}else{
		if(($ib % $record_min_2==0)or($ib % $record_min_1==0)or($ib % $record_min_3==1)or($ib % $record==0)){
			if(($ib % $record_min_2==0)){
				$jml_chek=3;
				if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
					for($jb=1;$jb<=$jml_chek;$jb++){
						//echo $arr_baris[0][isi];
						//echo $arr_baris[-1][isi];
						echo str_replace('jamal','jamal 1',$arr_baris[-1][isi]);
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}
			}elseif(($ib % $record_min_3)==1){
				$jml_chek=4;
				//echo "xxxxx $ib -- $pr_baris --".$arr_baris[$pr_baris][isi]."---- ".$arr_baris[$pr_baris+$jml_chek][isi]."<br>";
				//echo "xxxxx $ib -- $pr_baris -- $record_min_3 ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
				if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis5){
					//echo "masukkkkkkkkkkkkkkk $jenis5";
					for($jb=1;$jb<=10;$jb++){
						//echo $arr_baris[0][isi];
						//echo $arr_baris[-1][isi];
						echo str_replace('jamal','jamal 2',$arr_baris[-1][isi]);
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}
			}elseif(($ib % $record_min_1==0)){
				//echo " test $pr_baris -- $ib ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
				$jml_chek=2;
				if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3){
					for($jb=1;$jb<=$jml_chek;$jb++){
						//echo $arr_baris[0][isi];
						echo str_replace('jamal','jamal 3',$arr_baris[-1][isi]);
						//echo $arr_baris[-1][isi];
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}elseif($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2 and $arr_baris[$pr_baris+$jml_chek+1][jenis]==$jenis3){
					for($jb=0;$jb<=$jml_chek-1;$jb++){
						//echo $arr_baris[0][isi];
						echo str_replace('jamal','jamal OK',$arr_baris[-1][isi]);
						//echo $arr_baris[-1][isi];
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}elseif($arr_baris[$pr_baris+1][jenis]=="account" and $arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2 and $arr_baris[$pr_baris+5][jenis]==$jenis3){
					for($jb=1;$jb<=$jml_chek;$jb++){
						//echo $arr_baris[0][isi];
						echo str_replace('jamal','jamal OPO THO',$arr_baris[-1][isi]);
						//echo $arr_baris[-1][isi];
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}
			}elseif(($ib % $record==0)){
				$jml_chek=1;
				//echo " test $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
				if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2){
					for($jb=1;$jb<=$jml_chek;$jb++){
						echo str_replace('jamal','jamal 4',$arr_baris[-1][isi]);
						//echo $arr_baris[-1][isi];
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}elseif($arr_baris[$pr_baris][jenis]==$jenis1){
					echo str_replace('jamal','jamal 5',$arr_baris[-1][isi]);
					//echo $arr_baris[-1][isi];
					//$pr_baris--;
					$ib++;
				}
			}

			if($print_n){
				//echo "$ib -- $pr_baris -- ".$arr_baris[$pr_baris][isi];
				//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
				echo $arr_baris[$pr_baris][isi];
				$pr_baris++;
			}
		}else{
			//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
			echo $arr_baris[$pr_baris][isi];
			$pr_baris++;
		}
		//}
	}
	return $arr_baris;
	//echo $arr_baris[$pr_baris][isi];
}
*/

function arr_nggawe_halaman_harta($max_record,$arr_baris,$jenis2,$jenis3,$jenis4,$jenis6){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$record=$max_record;
	$posisi_ideal=43;
	$baris_ideal=($record*ceil(count($arr_baris)/$record));
	$jml_hal=$baris_ideal/$record;
	$record=$posisi_ideal;
	$record_min_2=$record-2;
	$record_min_1=$record-1;
	$record_min_3=$record-3;
	echo $arr_baris[0][isi];
	$pr_baris=1;
	for($h=0;$h<=$jml_hal;$h++){
		for($ib=1;$ib<=$record+1;$ib++){
			$print_n=true;
			if(($ib % ($posisi_ideal+1)==0)){
				//echo " Opo Tho $pr_baris -- $baris_ideal --$ib "."<br>";
				if($pr_baris<=(count($arr_baris)-1)){
					for($jb=1;$jb<=2;$jb++){
						echo str_replace('jamal','jamal bt',$arr_baris[-1][isi]);
						$ib++;
					}
				}
			}else{
				if(($ib % $record_min_2==0) or ($ib % $record_min_1==0) or ($ib % $record_min_3==0) or ($ib % $record==0)){
					if(($ib % $record_min_3)==0){
						$jml_chek=4;
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
							//echo "masukkkkkkkkkkkkkkk $jenis5";
							for($jb=1;$jb<=10;$jb++){
								//echo $arr_baris[0][isi];
								//echo $arr_baris[-1][isi];
								echo str_replace('jamal','jamal entek',$arr_baris[-1][isi]);
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}
					}elseif(($ib % $record_min_2==0)){
						$jml_chek=3;
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
							for($jb=1;$jb<=$jml_chek;$jb++){
								//echo $arr_baris[0][isi];
								//echo $arr_baris[-1][isi];
								echo str_replace('jamal','jamal 1',$arr_baris[-1][isi]);
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}
					}elseif(($ib % $record_min_1==0)){
						//echo " test $pr_baris -- $ib -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
						$jml_chek1=1;
						$jml_chek=2;
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3){
							for($jb=1;$jb<=$jml_chek;$jb++){
								//echo $arr_baris[0][isi];
								echo str_replace('jamal','jamal 3',$arr_baris[-1][isi]);
								//echo $arr_baris[-1][isi];
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}elseif($arr_baris[$pr_baris+$jml_chek1][jenis]==$jenis6 and $jenis6!="" and $arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2){
							for($jb=1;$jb<=4;$jb++){
								//echo $arr_baris[0][isi];
								echo str_replace('jamal','jamal tenanan',$arr_baris[-1][isi]);
								//echo $arr_baris[-1][isi];
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}
					}elseif(($ib % $record==0)){
						$jml_chek=1;
						//echo " test $pr_baris -- ".$arr_baris[$pr_baris][jenis]."<br>";
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2){
							for($jb=1;$jb<=3;$jb++){
								echo str_replace('jamal','jamal 4',$arr_baris[-1][isi]);
								//echo $arr_baris[-1][isi];
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}elseif($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis6 and $jenis6!=""){
							for($jb=1;$jb<=3;$jb++){
								echo str_replace('jamal','jamalan',$arr_baris[-1][isi]);
								//echo $arr_baris[-1][isi];
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}
					}
					if($print_n){
						//echo "$ib -- $pr_baris -- ".$arr_baris[$pr_baris][isi];
						//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
						echo $arr_baris[$pr_baris][isi];
						$pr_baris++;
					}
				}else{
					//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
					echo $arr_baris[$pr_baris][isi];
					$pr_baris++;
				}
			}
		}
		if($pr_baris>=(count($arr_baris)-1)){
			//if(($ib % ($posisi_ideal+1) ==0) and ($baris_ideal-$pr_baris)>18){
			break;
		}
	}
	return $arr_baris;
	//echo $arr_baris[$pr_baris][isi];
}

function nggawe_halaman_buku($max_record,$arr_baris,$jenis2,$jenis3,$jenis4,$jenis5="tanda_tangan"){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$record=$max_record;
	$baris_ideal=($record*ceil(count($arr_baris)/$record))+10;
	$record_min_2=$record-2;
	$record_min_1=$record-1;
	echo $arr_baris[0][isi];
	$pr_baris=1;
	for($ib=1;$ib<=$baris_ideal;$ib++){
		$print_n=true;	
		//if(($ib % 43==0)or($ib % 44==0)){
		//echo str_replace('xxx','yyy',$arr_baris[0][isi]);
		//}else{
		if(($ib % $record_min_2==0)or($ib % $record_min_1==0)or($ib % $record_min_3==1)or($ib % $record==0)){
			if(($ib % $record_min_2==0)){
				$jml_chek=3;
				if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
					for($jb=1;$jb<=$jml_chek;$jb++){
						//echo $arr_baris[0][isi];
						//echo $arr_baris[-1][isi];
						echo str_replace('jamal','jamal 1',$arr_baris[-1][isi]);
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}
			}elseif(($ib % $record_min_1==0)){
				$jml_chek=2;
				if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3){
					for($jb=1;$jb<=$jml_chek;$jb++){
						//echo $arr_baris[0][isi];
						echo str_replace('jamal','jamal 3',$arr_baris[-1][isi]);
						//echo $arr_baris[-1][isi];
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}
			}elseif(($ib % $record==0)){
				$jml_chek=1;
				//echo " test $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
				if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2){
					for($jb=1;$jb<=$jml_chek;$jb++){
						echo str_replace('jamal','jamal 4',$arr_baris[-1][isi]);
						//echo $arr_baris[-1][isi];
						//$pr_baris--;
						$ib++;
					}
					$print_n=false;
				}
			}

			if($print_n){
				//echo "$ib -- $pr_baris -- ".$arr_baris[$pr_baris][isi];
				//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
				echo $arr_baris[$pr_baris][isi];
				$pr_baris++;
			}
		}else{
			//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
			echo $arr_baris[$pr_baris][isi];
			$pr_baris++;
		}
		//}
	}
	return $arr_baris;
	//echo $arr_baris[$pr_baris][isi];
}

function nggawe_halaman_laba_rugi($max_record,$arr_baris,$jenis1,$jenis2,$jenis3,$jenis5="tanda_tangan"){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;

	$record=$max_record;
	$posisi_ideal=43;
	$baris_ideal=($record*ceil(count($arr_baris)/$record));
	$jml_hal=$baris_ideal/$record;
	$record=$posisi_ideal;
	$record_min_4=$record-4;
	$record_min_telu=$record-3;
	$record_min_2=$record-2;
	$record_min_1=$record-1;
	$record_min_3=$record-6;
	echo $arr_baris[0][isi];
	$pr_baris=1;
	for($h=0;$h<=$jml_hal;$h++){
		for($ib=1;$ib<=$record+1;$ib++){
			$print_n=true;
			if(($ib % ($posisi_ideal+1) ==0)){
				if($pr_baris<=(count($arr_baris)-1)){
					for($jb=1;$jb<=1;$jb++){
						echo str_replace('jamal','jamal bt',$arr_baris[-1][isi]);
						$ib++;
					}
				}
			}else{
				if(($ib % $record_min_2==0)or($ib % $record_min_1==0)or($ib % $record_min_3==0)or($ib % $record==0)or($ib % $record_min_telu==0)){
					if(($ib % $record_min_2==0)){
						$jml_chek=3;
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3 and $arr_baris[$pr_baris+$jml_chek+1][jenis]==$jenis5){
							for($jb=0;$jb<=$jml_chek;$jb++){
								echo str_replace('jamal','jamal ngganteng',$arr_baris[-1][isi]);
								$ib++;
							}
							$print_n=false;
						}
					}elseif(($ib % $record_min_3)==0 and $ib!=1){
						$jml_chek=4;
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis5){
							for($jb=1;$jb<=8;$jb++){
								echo str_replace('jamal','jamal 2',$arr_baris[-1][isi]);
								$ib++;
							}
							$print_n=false;
						}
					}elseif(($ib % $record_min_1==0)){
						$jml_chek=2;
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis3 and $arr_baris[$pr_baris+1][jenis]==$jenis2){
							for($jb=0;$jb<=$jml_chek;$jb++){
								echo str_replace('jamal','jamal 9',$arr_baris[-1][isi]);
								$ib++;
							}
							$print_n=false;
						}elseif($arr_baris[$pr_baris][jenis]==$jenis1){
							for($jb=0;$jb<=$jml_chek;$jb++){
								echo str_replace('jamal','jamal piro',$arr_baris[-1][isi]);
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}
					}elseif(($ib % $record==0)){
						$jml_chek=1;
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2){
							for($jb=0;$jb<=$jml_chek+1;$jb++){
								echo str_replace('jamal','jamal 4',$arr_baris[-1][isi]);
								$ib++;
							}
							$print_n=false;
						}elseif($arr_baris[$pr_baris][jenis]==$jenis1){
							//echo " test $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
							for($jb=0;$jb<=$jml_chek;$jb++){
								echo str_replace('jamal','jamal 5',$arr_baris[-1][isi]);
								$ib++;
							}
						}
					}
					if($print_n){
						echo $arr_baris[$pr_baris][isi];
						$pr_baris++;
					}
				}else{
					echo $arr_baris[$pr_baris][isi];
					$pr_baris++;
				}
			}
		}
/*		for($j=$ib;$j<=$max_record;$j++){
			if(($baris_ideal-$pr_baris)>5){
			//if(($baris_ideal-$pr_baris)>5 and ($ib*2-$pr_baris)!=1){
				echo str_replace('jamal',"jamal 6 $pr_baris -- $ib -- $baris_ideal",$arr_baris[-1][isi]);
				//echo $arr_baris[-1][isi];
				$ib++;
			}
		}
*/		if($pr_baris>=(count($arr_baris)-1)){
			//echo "testtt";
			break;	
		}

	}
	return $arr_baris;
	//echo $arr_baris[$pr_baris][isi];
}

function nggawe_halaman_neraca_lajur($max_record,$arr_baris,$jenis1,$jenis2,$jenis3,$jenis4,$jenis5="tanda_tangan"){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$record=$max_record;
	$posisi_ideal=27;
	$baris_ideal=($record*ceil(count($arr_baris)/$record));
	$jml_hal=$baris_ideal/$record;
	$record=$posisi_ideal;
	$record_min_2=$record-2;
	$record_min_1=$record-1;
	$record_min_3=$record-5;
	echo $arr_baris[0][isi];
	$pr_baris=1;
	//echo "$jml_hal";
	for($h=0;$h<=$jml_hal;$h++){
		//echo "$h <br>";
		for($ib=1;$ib<=$record+1;$ib++){
			$print_n=true;
			//if(($ib % ($posisi_ideal+1) ==0) and ($baris_ideal-$pr_baris)>18){
			if(($ib % ($posisi_ideal+1) ==0)){
				//echo " Opo Tho $pr_baris -- $baris_ideal --$ib "."<br>";
				if($pr_baris<=(count($arr_baris)-1)){
					for($jb=1;$jb<=2;$jb++){
						echo str_replace('jamal','jamal bt',$arr_baris[-1][isi]);
						$ib++;
					}
				}
			}else{
				//if(($ib % 43==0)or($ib % 44==0)){
				//echo str_replace('xxx','yyy',$arr_baris[0][isi]);
				//}else{
				if(($ib % $record_min_2==0) or ($ib % $record_min_1==1) or ($ib % $record==0) or ($ib % $record_min_3==0)){
					if(($ib % $record_min_2==0)){
						$jml_chek=3;
						//echo " ehmehemset $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4 and $jenis4<>""){
							for($jb=1;$jb<=$jml_chek+2;$jb++){
								//echo $arr_baris[0][isi];
								//echo $arr_baris[-1][isi];
								echo str_replace('jamal','jamal 1',$arr_baris[-1][isi]);
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}

					}elseif(($ib % $record_min_1==0)){
						$jml_chek=2;
						//echo " testing $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4){
							for($jb=1;$jb<=$jml_chek;$jb++){
								//echo $arr_baris[0][isi];
								echo str_replace('jamal','jamal 3',$arr_baris[-1][isi]);
								//echo $arr_baris[-1][isi];
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}
					}elseif(($ib % $record)==0){
						$jml_chek=1;
						//echo " test $pr_baris -- $ib ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2 and $arr_baris[$pr_baris+$jml_chek+1][jenis]<>$jenis2){
							for($jb=1;$jb<=3;$jb++){
								echo str_replace('jamal',"$ib $jenis2",$arr_baris[-1][isi]);
								//echo $arr_baris[-1][isi];
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}

					}
					if($print_n){
						//echo "$ib -- $pr_baris -- ".$arr_baris[$pr_baris][isi];
						//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
						echo $arr_baris[$pr_baris][isi];
						$pr_baris++;
					}
				}else{
					//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
					echo $arr_baris[$pr_baris][isi];
					$pr_baris++;
				}			//}
			}			//}
		}
		//echo "testtt $pr_baris ".count($arr_baris)."<br>";
		if($pr_baris>=(count($arr_baris)-1)){
			//echo "testtt";
			exit;
		}
	}
	return $arr_baris;
	//echo $arr_baris[$pr_baris][isi];
}

function nggawe_halaman_neraca_konsolidasi($max_record,$arr_baris,$jenis1,$jenis2,$jenis3,$jenis4,$jenis5="tanda_tangan"){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$record=$max_record;
	$posisi_ideal=27;
	$baris_ideal=($record*ceil(count($arr_baris)/$record));
	$jml_hal=$baris_ideal/$record;
	$record=$posisi_ideal;
	$record_min_2=$record-2;
	$record_min_1=$record-1;
	//$record_min_3=$record-5;
	echo $arr_baris[0][isi];
	$pr_baris=1;
	//echo "$jml_hal";
	for($h=0;$h<=$jml_hal;$h++){
		//echo "$h <br>";
		for($ib=1;$ib<=$record+1;$ib++){
			$print_n=true;
			if(($ib % ($posisi_ideal+1) ==0)){
				for($jb=1;$jb<=2;$jb++){
					echo str_replace('jamal','jamal bt',$arr_baris[-1][isi]);
					$ib++;
				}
			}else{
				//if(($ib % 43==0)or($ib % 44==0)){
				//echo str_replace('xxx','yyy',$arr_baris[0][isi]);
				//}else{
				if(($ib % $record_min_2==0) or ($ib % $record_min_1==0) or ($ib % $record==0) or ($ib % $record_min_3==0)){
					if(($ib % $record_min_2==0)){
						$jml_chek=3;
						//echo " ehmehemset $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4 and $arr_baris[$pr_baris+2][jenis]==$jenis2){
							for($jb=1;$jb<=$jml_chek;$jb++){
								//echo $arr_baris[0][isi];
								//echo $arr_baris[-1][isi];
								echo str_replace('jamal','jamal 1',$arr_baris[-1][isi]);
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}

					}elseif(($ib % $record_min_1==0)){
						$jml_chek=2;
						//echo " testing $pr_baris -- ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
						if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis4 and $arr_baris[$pr_baris+1][jenis]==$jenis2){
							for($jb=1;$jb<=$jml_chek;$jb++){
								//echo $arr_baris[0][isi];
								echo str_replace('jamal','jamal 3',$arr_baris[-1][isi]);
								//echo $arr_baris[-1][isi];
								//$pr_baris--;
								$ib++;
							}
							$print_n=false;
						}
						//}elseif(($ib % $record==0) or ($ib % $record==1)){
				}elseif(($ib % $record)==0){
					$jml_chek=1;
					//echo " test $pr_baris -- $ib ".$arr_baris[$pr_baris+$jml_chek][jenis]."<br>";
					if($arr_baris[$pr_baris+$jml_chek][jenis]==$jenis2){
						for($jb=1;$jb<=3;$jb++){
							echo str_replace('jamal',"$ib $jenis2",$arr_baris[-1][isi]);
							//echo $arr_baris[-1][isi];
							//$pr_baris--;
							$ib++;
						}
						$print_n=false;
					}

				}
				if($print_n){
					//echo "$ib -- $pr_baris -- ".$arr_baris[$pr_baris][isi];
					//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
					echo $arr_baris[$pr_baris][isi];
					$pr_baris++;
				}
				}else{
					//echo str_replace('&nbsp;',"$ib",$arr_baris[$pr_baris][isi]);
					echo $arr_baris[$pr_baris][isi];
					$pr_baris++;
				}			//}
			}			//}
		}
		//echo "testtt $pr_baris ".count($arr_baris)."<br>";
		if($pr_baris>=(count($arr_baris)-1)){
		//echo "testtt";
		break;
		}
	}
	return $arr_baris;
	//echo $arr_baris[$pr_baris][isi];

}

function arr_summary_account($bulan,$tahun,$panjang=3,$kode_tengahe=""){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$str_debet_lalu="dsll + ";
	$str_kredit_lalu="ksll + ";
	for($i=1;$i<=$bulan;$i++){
	$str_debet_ini.="dt_$i + ";
	$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	if($str_debet_ini==""){
		$str_debet_ini="0";
	}
	if($str_kredit_ini==""){
		$str_kredit_ini="0";
	}
	$bulan=trim(str_replace("0","",$bulan));	
	$str_debet=$str_debet_lalu.$str_debet_ini;
	$str_kredit=$str_kredit_lalu.$str_kredit_ini;
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
	if($kode_tengahe==""){
		$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($cdivisi_account)." group by tahun,substr(account_kode,1,$panjang)";
	}else{
		$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($kode_tengahe)." group by tahun,substr(account_kode,1,$panjang)";
	}
	$res=dbresult($sql);//echo $sql;
	echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$acc=$r[account_kode];
		$kode_awal=substr($acc,0,3);
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];
		//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

		$saldo=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
		$arr_temp[$acc]["saldo"]=$saldo==""?0:$saldo;
		$arr_temp[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp[$acc]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
		$arr_temp[$acc]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
		$arr_temp[$acc]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
		$arr_temp[$acc]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
		$arr_temp[$acc]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
		$arr_temp[$acc]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;
		$arr_temp[$acc]["account_kode"]=1;	
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;

}

function arr_summary_account2($bulan,$tahun,$panjang=12,$kode_tengahe=""){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$str_debet_lalu="dsll + ";
	$str_kredit_lalu="ksll + ";
	for($i=1;$i<=$bulan;$i++){
	$str_debet_ini.="dt_$i + ";
	$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	if($str_debet_ini==""){
		$str_debet_ini="0";
	}
	if($str_kredit_ini==""){
		$str_kredit_ini="0";
	}
	$bulan=trim(str_replace("0","",$bulan));	
	$str_debet=$str_debet_lalu.$str_debet_ini;
	$str_kredit=$str_kredit_lalu.$str_kredit_ini;
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
//	$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($cdivisi_account)." group by tahun,substr(account_kode,1,$panjang)";
	if($kode_tengahe==""){
		$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($cdivisi_account)." group by tahun,substr(account_kode,1,$panjang)";
	}else{
		$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($kode_tengahe)." group by tahun,substr(account_kode,1,$panjang)";
	}
	$res=dbresult($sql);//echo $sql;
	//echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$acc=$r[account_kode];
		$kode_awal=substr($acc,0,3);
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];
		//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

		$saldo=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
		$arr_temp[$acc]["saldo"]=$saldo==""?0:$saldo;
		$arr_temp[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp[$acc]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
		$arr_temp[$acc]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
		$arr_temp[$acc]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
		$arr_temp[$acc]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
		$arr_temp[$acc]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
		$arr_temp[$acc]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;
	
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;

}

function arr_summary_account4($bulan,$tahun,$bulan2,$tahun2,$panjang=3){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;

	for($i=1;$i<=$bulan2;$i++){
		$sql="select substr(account_kode,1,$panjang) as account_kode, sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu, sum(dt_$i) as jml_debet, sum(kt_$i) as jml_kredit from tbl_summary_account where tahun=$tahun ".sql_account($cdivisi_account)." group by tahun,substr(account_kode,1,$panjang)";
		$res=dbresult($sql);
		while($r=odbc_fetch_array($res,0)){
			$acc=$r[account_kode];
	//		echo $sql."<br>";
			$saldo=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
			$arr_temp[$acc]["saldo"]["dt_$i"]=$saldo==""?0:$saldo;
			$arr_temp[$acc]["kredit"]["dt_$i"]=$r[jml_debet]==""?0:$r[jml_debet];
			$arr_temp[$acc]["debet"]["dt_$i"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		}	
	}	

/*   echo "<pre>";
   print_r($arr_temp);
   echo "</pre>";
*/
return $arr_temp;

}

function arr_summary_account5($bulan,$tahun,$bulan2,$tahun2,$panjang=3){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$bulan=$bulan=="01"?1:$bulan;
	$bulan=$bulan=="02"?2:$bulan;
	$bulan=$bulan=="03"?3:$bulan;
	$bulan=$bulan=="04"?4:$bulan;
	$bulan=$bulan=="05"?5:$bulan;
	$bulan=$bulan=="06"?6:$bulan;
	$bulan=$bulan=="07"?7:$bulan;
	$bulan=$bulan=="08"?8:$bulan;
	$bulan=$bulan=="09"?9:$bulan;
	if($bulan=="1"){
		$str_debet_lalu="dsll + ";
		$str_kredit_lalu="ksll + ";
	}
//	$str_debet_lalu=substr($str_debet_lalu,0,strlen($str_debet_lalu)-4);
//	$str_kredit_lalu=substr($str_kredit_lalu,0,strlen($str_kredit_lalu)-4);
	for($i=$bulan;$i<=$bulan2;$i++){
		$str_debet_ini.="dt_$i + ";
		$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	if($str_debet_ini==""){
		$str_debet_ini="0";
	}
	if($str_kredit_ini==""){
		$str_kredit_ini="0";
	}
	$bulan=trim(str_replace("0","",$bulan));	
	if($bulan=="1"){
		$str_debet=$str_debet_lalu.$str_debet_ini;
		$str_kredit=$str_kredit_lalu.$str_kredit_ini;
	}else{
		$str_debet=$str_debet_ini;
		$str_kredit=$str_kredit_ini;
	}
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
	$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($cdivisi_account)." group by tahun,substr(account_kode,1,$panjang)";
	$res=dbresult($sql);//echo $sql;
	//echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$acc=$r[account_kode];
		$kode_awal=substr($acc,0,3);
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];
		//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

		$saldo=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
		$arr_temp[$acc]["saldo"]=$saldo==""?0:$saldo;
		$arr_temp[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp[$acc]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
		$arr_temp[$acc]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
		$arr_temp[$acc]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
		$arr_temp[$acc]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
		$arr_temp[$acc]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
		$arr_temp[$acc]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;
	
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;

}

function arr_summary_account10($bulan,$tahun,$bulan2,$tahun2,$panjang=12){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$bulan=$bulan=="01"?1:$bulan;
	$bulan=$bulan=="02"?2:$bulan;
	$bulan=$bulan=="03"?3:$bulan;
	$bulan=$bulan=="04"?4:$bulan;
	$bulan=$bulan=="05"?5:$bulan;
	$bulan=$bulan=="06"?6:$bulan;
	$bulan=$bulan=="07"?7:$bulan;
	$bulan=$bulan=="08"?8:$bulan;
	$bulan=$bulan=="09"?9:$bulan;
	if($bulan=="1"){
		$str_debet_lalu="dsll + ";
		$str_kredit_lalu="ksll + ";
	}
//	$str_debet_lalu=substr($str_debet_lalu,0,strlen($str_debet_lalu)-4);
//	$str_kredit_lalu=substr($str_kredit_lalu,0,strlen($str_kredit_lalu)-4);
	for($i=$bulan;$i<=$bulan2;$i++){
		$str_debet_ini.="dt_$i + ";
		$str_kredit_ini.="kt_$i + ";
	}
	$str_debet_ini=substr($str_debet_ini,0,strlen($str_debet_ini)-3);
	$str_kredit_ini=substr($str_kredit_ini,0,strlen($str_kredit_ini)-3);
	if($str_debet_ini==""){
		$str_debet_ini="0";
	}
	if($str_kredit_ini==""){
		$str_kredit_ini="0";
	}
	$bulan=trim(str_replace("0","",$bulan));	
	if($bulan=="1"){
		$str_debet=$str_debet_lalu.$str_debet_ini;
		$str_kredit=$str_kredit_lalu.$str_kredit_ini;
	}else{
		$str_debet=$str_debet_ini;
		$str_kredit=$str_kredit_ini;
	}
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
	$sql="select substr(account_kode,1,$panjang) as account_kode,sum(dsll) as jml_debet_lalu,sum(ksll) as jml_kredit_lalu,sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit,sum($str_debet_ini) as jml_debet_ini,sum($str_kredit_ini) as jml_kredit_ini from tbl_summary_account where tahun=$tahun ".sql_account($cdivisi_account)." group by tahun,substr(account_kode,1,$panjang)";
	$res=dbresult($sql);//echo $sql;
	//echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$acc=$r[account_kode];
		$kode_awal=substr($acc,0,3);
		$saldo_lalu=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_lalu]-$r[jml_debet_lalu]:$r[jml_debet_lalu]-$r[jml_kredit_lalu];
		$saldo_ini=strpos($tanda_account,$kode_awal)>0?$r[jml_kredit_ini]-$r[jml_debet_ini]:$r[jml_debet_ini]-$r[jml_kredit_ini];
		//echo "$saldo_ini=$r[jml_debet_ini]-$r[jml_kredit_ini] <br>";

		$saldo=strpos($tanda_account,$kode_awal)>0?($r[jml_kredit]-$r[jml_debet]):($r[jml_debet]-$r[jml_kredit]);
		$arr_temp[$acc]["saldo"]=$saldo==""?0:$saldo;
		$arr_temp[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp[$acc]["debet_lalu"]=$r[jml_debet_lalu]==""?0:$r[jml_debet_lalu];
		$arr_temp[$acc]["kredit_lalu"]=$r[jml_kredit_lalu]==""?0:$r[jml_kredit_lalu];;
		$arr_temp[$acc]["saldo_lalu"]=$saldo_lalu==""?0:$saldo_lalu;
		$arr_temp[$acc]["debet_ini"]=$r[jml_debet_ini]==""?0:$r[jml_debet_ini];
		$arr_temp[$acc]["kredit_ini"]=$r[jml_kredit_ini]==""?0:$r[jml_kredit_ini];;
		$arr_temp[$acc]["saldo_ini"]=$saldo_ini==""?0:$saldo_ini;
	
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;

}


function arr_nama_buku_tambahan($tahun,$no_bukti,$no_transaksi,$divisi_kode){
	global $cdivisi_account,$cdivisi_kode;
	global $tanda_account,$tanda_lb;
	$arr_kdaccount=split(",",$cdivisi_account);
	while(list($key,$nilai)=each($arr_kdaccount)){	
		$sql="select keterangan from tbl_transaksi where tahun='$tahun' and no_bukti='$no_bukti' and no_transaksi='$no_transaksi' and data_divisi_kode='$divisi_kode'";
		$res=dbresult($sql);//echo $sql;
		//echo $sql."<br>";
		while($r=odbc_fetch_array($res,0)){
			$arr_temp["keterangan"]=$r[keterangan];
		}
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;
}


function arr_nama_ikhtisar($tahun){
	global $cdivisi_account,$cdivisi_kode;
	global $tanda_account,$tanda_lb;
	$arr_kdaccount=split(",",$cdivisi_account);
	while(list($key,$nilai)=each($arr_kdaccount)){	
		$sql="select account_kode,account_nama from tbl_account where tahun='$tahun' and account_kode like('4%0.%')".sql_account($nilai)." and account_kode like('%0.%%%.%') group by account_kode,account_nama order by account_kode";
		$res=dbresult($sql);//echo $sql;
		//echo $sql."<br>";
		while($r=odbc_fetch_array($res,0)){
			$acc=substr($r[account_kode],0,11);
			$kode1=substr($r[account_kode],0,2);
			$kode2=substr($r[account_kode],4,7);
			$arr_temp[$kode1][$kode2]["keterangan"]=$r[account_nama];
			$arr_temp[$kode1][$kode2]["account_kode"]=$acc;
		}
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;
}

function arr_nama_60($tahun){
	global $cdivisi_account,$cdivisi_kode;
	global $tanda_account,$tanda_lb;
	$arr_kdaccount=split(",",$cdivisi_account);
	while(list($key,$nilai)=each($arr_kdaccount)){	
		$sql="select account_kode,account_nama from tbl_account where tahun='$tahun' and account_kode like('400.%')".sql_account($nilai)." and account_kode like('%0.%%%.%') group by account_kode,account_nama order by account_kode";
		$res=dbresult($sql);//echo $sql;
		//echo $sql."<br>";
		while($r=odbc_fetch_array($res,0)){
			$acc=substr($r[account_kode],0,11);
			$kode1=substr($r[account_kode],9,2);
			$kode2=substr($r[account_kode],4,3);
			$keterangan=$r[account_nama];
			$new_ket=str_replace("HSL.","","$keterangan");
			$arr_temp[$kode1][$kode2]["keterangan"]=$new_ket;
			//$arr_temp[$kode1][$kode2]["account_kode"]=$acc;
		}
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	*/
	return $arr_temp;
}

/*
function arr_qry_transaksi2($tgl1,$tgl2,$panjang=12){
	global $cdivisi_account,$cdivisi_kode;
	global $tanda_account,$tanda_lb;
	$sql="select account_kode,sum(debet) as jml_debet,sum(kredit) as jml_kredit,sum(debet)-sum(kredit) as jml_saldo from qry_transaksi_dk2 where tgl_transaksi>='$tgl1' and tgl_transaksi<='$tgl2' and (data_divisi_kode='$cdivisi_kode' or data_divisi_kode like '$cdivisi_kode.%') group by account_kode";
	$res=dbresult($sql);
//	echo $sql."<br>";
	while($r=odbc_fetch_array($res,0)){
		$acc=$r[account_kode];

		$arr_temp[$acc]["debet"]=$r[jml_debet]==""?0:$r[jml_debet];
		$arr_temp[$acc]["kredit"]=$r[jml_kredit]==""?0:$r[jml_kredit];;
		$arr_temp[$acc]["saldo"]=$r[jml_saldo]==""?0:$r[jml_saldo];
	
	}
	/*
	echo "<pre>";
	print_r($arr_temp);
	echo "</pre>";
	
	return $arr_temp;

}
*/
function baca_saldo($account_kode,$bulan,$tahun){
/*
	for($i=1;$i<=$bulan;$i++){
	$str_debet.="dt_$i + ";
	$str_kredit.="kt_$i + ";
	}
	$str_debet=substr($str_debet,0,strlen($str_debet)-3);
	$str_kredit=substr($str_kredit,0,strlen($str_kredit)-3);
//	$sql="select  sum($str_debet) as jml_debet,sum($str_kredit) as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode%'";
	$sql="select  $str_debet as jml_debet,$str_kredit as jml_kredit from qry_summary_account where tahun=$tahun and account_kode ='$account_kode'";
	$res=dbresult($sql);
	$r=odbc_fetch_array($res,0);
	//echo $sql."<br>";
	$saldo=$r[jml_debet]-$r[jml_kredit];
	return $saldo;
*/
}
/*
function baca_permisi(){
	global $permisi;
	global $cuserid;
	global $clevel;
	global $st_level_user;
	switch($clevel){
		//User Default
		case 1:
			$permisi["add"]="izin";
			$permisi["edit"]="izin";
			$permisi["delete"]="izin";
			$permisi["access"]="corporate";
			$permisi["approve"]="izin";
			break;
			//User
		case 2:
			$permisi["add"]="izin";
			$permisi["edit"]="izin";
			$permisi["delete"]="izin";
			$permisi["access"]="divisi";
			$permisi["approve"]="izin";
			break;
			//Administrator
		case 3:
			$permisi["add"]="tolak";
			$permisi["edit"]="tolak";
			$permisi["delete"]="tolak";
			$permisi["access"]="corporate";
			$permisi["approve"]="tolak";
			break;
			//Not Access
		case 4:
			$permisi["add"]="tolak";
			$permisi["edit"]="tolak";
			$permisi["delete"]="tolak";
			$permisi["access"]="corporate";
			$permisi["approve"]="tolak";
			break;
		case 5:
			$permisi["add"]="tolak";
			$permisi["edit"]="tolak";
			$permisi["delete"]="tolak";
			$permisi["access"]="divisi";
			$permisi["approve"]="tolak";
			break;

	}
}
*/
function baca_permisi($sub_f_id){
	global $permisi;
	global $cuserid;
	global $st_level_user;
	$sql="select * from tbl_user a inner join tbl_menu_peran b on a.level_akses=cast(b.id_peran as bigint) where a.user_id=$cuserid and b.sub_f_id=$sub_f_id";
	$res=dbresult($sql);//echo "$sql<br>";
	$jml=odbc_num_rows($res);
	if($jml>0){
		$r=odbc_fetch_array($res);
		switch($r[menu_access]){
			case 5:
					$permisi["add"]="izin";
					$permisi["edit"]="izin";
					$permisi["delete"]="izin";
					$permisi["access"]="izin";
					$permisi["copy"]="izin";
					$permisi["save"]="izin";
					$permisi["print"]="izin";
					$permisi["approve"]="izin";
					break;
					//AKSES ALL
			case 4:
					$permisi["add"]="izin";
					$permisi["edit"]="izin";
					$permisi["delete"]="izin";
					$permisi["access"]="izin";
					$permisi["copy"]="tolak";
					$permisi["save"]="izin";
					$permisi["print"]="izin";
					$permisi["approve"]="tolak";
					break;
					//AKSES READ/WRITE
			case 3:
					$permisi["add"]="tolak";
					$permisi["edit"]="izin";
					$permisi["delete"]="tolak";
					$permisi["access"]="izin";
					$permisi["copy"]="tolak";
					$permisi["save"]="tolak";
					$permisi["print"]="tolak";
					$permisi["approve"]="tolak";
					break;
					//AKSES READ/EDIT
			case 2:
					$permisi["add"]="tolak";
					$permisi["edit"]="tolak";
					$permisi["delete"]="tolak";
					$permisi["access"]="izin";
					$permisi["copy"]="tolak";
					$permisi["save"]="tolak";
					$permisi["print"]="izin";
					$permisi["approve"]="tolak";
					break;
					//AKSES READ
			case 1:
					$permisi["add"]="tolak";
					$permisi["edit"]="tolak";
					$permisi["delete"]="tolak";
					$permisi["access"]="tolak";
					$permisi["copy"]="tolak";
					$permisi["save"]="tolak";
					$permisi["print"]="tolak";
					$permisi["approve"]="tolak";
					break;
					//AKSES NOT ACCESS
			case 0:
					$permisi["add"]="tolak";
					$permisi["edit"]="tolak";
					$permisi["delete"]="tolak";
					$permisi["access"]="tolak";
					$permisi["copy"]="tolak";
					$permisi["save"]="tolak";
					$permisi["print"]="tolak";
					$permisi["approve"]="tolak";
					break;
					//KOSONG
		}
	}
}

function baca_peran(){
	global $cuserid;
	global $st_level_user;
	$sql="select * from tbl_peran order by id_peran";
        echo $sql;
	$res=dbresult($sql);//echo "$sql<br>";
	$jml=odbc_num_rows($res);
	while($r=odbc_fetch_array($res,0)){
		$id_peran=$r[id_peran];
		$nama_peran=$r[nama_peran];
		$peran[$id_peran]=$nama_peran;
	}
	return $peran;
}

$bulan[1]="Jan";
$bulan[2]="Feb";
$bulan[3]="Mar";
$bulan[4]="Apr";
$bulan[5]="May";
$bulan[6]="Jun";
$bulan[7]="Jul";
$bulan[8]="Aug";
$bulan[9]="Sep";
$bulan[10]="Oct";
$bulan[11]="Nov";
$bulan[12]="Des";
$hp_berhasil=0;
$hp_gagal=0;


$arr_divisi[1]="Pusat";
$arr_divisi[2]="GM OP I";
$arr_divisi[3]="---DSU 1";
$arr_divisi[4]="---DSU 2";
$arr_divisi[5]="---DSU 3";
$arr_divisi[6]="---DPK";
$arr_divisi[7]="GM OP II";
$arr_divisi[8]="---DME";
$arr_divisi[9]="---DBG";
$arr_divisi[10]="---EPC";

$arr_rumus_divisi[1]=" and (divisi_kode='C' or divisi_kode='B' or divisi_kode='D' or divisi_kode='N' or  divisi_kode='E' or divisi_kode='F' or divisi_kode='O')";
$arr_rumus_divisi[2]=" and (divisi_kode='C' or divisi_kode='B' or divisi_kode='D' or divisi_kode='N')";
$arr_rumus_divisi[3]=" and divisi_kode='C'";
$arr_rumus_divisi[4]=" and divisi_kode='B'";
$arr_rumus_divisi[5]=" and divisi_kode='D'";
$arr_rumus_divisi[6]=" and divisi_kode='N'";
$arr_rumus_divisi[7]=" and (divisi_kode='E' or divisi_kode='F' or divisi_kode='O')";
$arr_rumus_divisi[8]=" and divisi_kode='E'";
$arr_rumus_divisi[9]=" and divisi_kode='F'";
$arr_rumus_divisi[10]=" and divisi_kode='O'";

function jumlah_tahap_rab($kode_tahap,$spk){
	global $kode,$set;
	$kode_tahap=trim($kode_tahap);
	if($kode_tahap<>""){
		$sql="select sum(tahap_total_rab) as \"jum\" from tbl_tahap_rab where tahap_kode_induk_rab='".trim($kode_tahap)."' and no_spk='$spk'";
		$result=dbresult($sql);
		$r=odbc_fetch_array($result);//echo $sql."<br>";
		if($r[jum]==""){
			$r[jum]=0;
		}
		$sql1="update tbl_tahap_rab set tahap_harga_satuan_rab='$r[jum]',tahap_total_rab=".$r[jum]." * tahap_volume_rab where tahap_kode_rab='$kode_tahap' and no_spk='$spk'";
		$resul1t=dbresult($sql1);//echo $sql1."<br>";

		$sql2="select * from tbl_tahap_rab where tahap_kode_rab='$kode_tahap' and no_spk='$spk'";
		$result2=dbresult($sql2);//echo $sql2."<br>";
		$f=odbc_fetch_array($result2);
		if(trim($f[tahap_kode_induk_rab])<>""){
			jumlah_tahap_rab(trim($f[tahap_kode_induk_rab]),$spk);
		}
	}
}

function jumlah_tahap_bq($kode_tahap,$spk){
	global $kode,$set;
	if(trim($kode_tahap)<>""){
		$sql="select sum(tahap_total_bq) as \"jum\" from tbl_tahap_bq where tahap_kode_induk_bq='$kode_tahap' and no_spk='$spk'";
		$result=dbresult($sql);
		$r=odbc_fetch_array($result);//echo $sql."<br>";
		if($r[jum]==""){
			$r[jum]=0;
		}
			$sql1="update tbl_tahap_bq set tahap_harga_satuan_bq='$r[jum]',tahap_total_bq=".$r[jum]."* tahap_volume_bq where tahap_kode_bq='$kode_tahap' and no_spk='$spk'";
			$resul1t=dbresult($sql1);//echo $sql1."<br>";
		$sql2="select * from tbl_tahap_bq where tahap_kode_bq='$kode_tahap' and no_spk='$spk'";
		$result2=dbresult($sql2);
		$f=odbc_fetch_array($result2);
		if(trim($f[tahap_kode_induk_bq])<>""){
			jumlah_tahap_bq(trim($f[tahap_kode_induk_bq]),$spk);
		}
	}
}
function jumlah_tahap_kendali($kode_tahap,$spk){
	global $kode,$set,$tgl_rab;
	if(trim($kode_tahap)<>""){
		$sql="select sum(tahap_total_kendali) as \"jum\" from tbl_tahap_kendali where tahap_kode_induk_kendali='$kode_tahap' and no_spk='$spk'  and tahap_tanggal_kendali='$tgl_rab'";
		$result=dbresult($sql);
		$r=odbc_fetch_array($result);#echo $sql."<br>";
		if($r[jum]==""){
			$r[jum]=0;
		}
			$sql1="update tbl_tahap_kendali set tahap_harga_satuan_kendali='$r[jum]',tahap_total_kendali=".$r[jum]." * tahap_volume_kendali where tahap_kode_kendali='$kode_tahap' and no_spk='$spk'  and tahap_tanggal_kendali='$tgl_rab'";
			$resul1t=dbresult($sql1);#echo $sql."<br>";
		$sql2="select * from tbl_tahap_kendali where tahap_kode_kendali='$kode_tahap' and no_spk='$spk'  and tahap_tanggal_kendali='$tgl_rab'";
		$result2=dbresult($sql2);
		$f=odbc_fetch_array($result2);
		if(trim($f[tahap_kode_induk_kendali])<>""){
			jumlah_tahap_kendali(trim($f[tahap_kode_induk_kendali]),$spk);
		}
	}
}
function datediff($per,$d1,$d2) {
	$d = $d2-$d1;
	switch($per) {
		case "yyyy": $d/=12;
		case "m": $d*=12*7/365.25;
		case "ww": $d/=7;
		case "d": $d/=24;
		case "h": $d/=60;
		case "n": $d/=60;
	}
	return round($d);
}

function dateadd($per,$n,$d) {
	switch($per) {
		case "yyyy": $n*=12;
		case "m":
			$d=mktime(date("H",$d),date("i",$d)
					,date("s",$d),date("n",$d)+$n
					,date("j",$d),date("Y",$d));
		$n=0; break;
		case "ww": $n*=7;
		case "d": $n*=24;
		case "h": $n*=60;
		case "n": $n*=60;
	}
	return $d+$n;
}

#start check password
function check_pass(){
	global $cusername;
	if($cusername!=""){

	}else{
		header("Location: http://192.168.0.13/keunindya/index.php");
	}
}

function bar_cari($nm_table,$aksi,$muncul_divisi="",$muncul_tahun=""){
	global $src_kata;
	global $src_jenis;
	global $src_divisi;
	global $src_tahun;
	global $cari;
	global $arr_divisi;
	$bgheader  = "darkblue";
	$result=dbresult($nm_table);
	$fnum= odbc_num_fields($result);
	$num = odbc_num_rows($result); 
	$txt = "<form action=$aksi? method=post><table width=100% border=0 align=center><tr bgcolor=white>";
	$txt .= "<td align=right width=70%> <font face=arial size=2 color=navy><b>
		Search : <input type=text size=30 name=src_kata value='$src_kata'> In : <select name=src_jenis><option value=-1>All</option>";
	for ($i=1; $i <= $fnum - 1; $i++){
		if($i == $src_jenis){
			$txt .= "<option value=$i selected>".odbc_field_name($result, $i)."</option>";
		}else{
			$txt .= "<option value=$i>".odbc_field_name($result, $i)."</option>";
		}
	}
	$txt .= "</select>";
	if($muncul_divisi <>""){
		$txt .= "
			Divisi : ".combo_array_new("src_divisi",$arr_divisi,$src_divisi)." Tahun :".combo_array_new("src_tahun",array("All"=>"All","2002"=>"2002","2003"=>"2003","2004"=>"2004","2005"=>"2005","2006"=>"2006","2007"=>"2007","2008"=>"2008","2009"=>"2009","2010"=>"2010"),$src_tahun)." ";
	}
	if($muncul_tahun <>""){
		$txt .= " Tahun :".combo_array_new("src_tahun",array("2002"=>"2002","2003"=>"2003","2004"=>"2004","2005"=>"2005","2006"=>"2006","2007"=>"2007","2008"=>"2008","2009"=>"2009","2010"=>"2010"),$src_tahun)." ";
	}

	$txt .= "
		</b></td><td align=left width=30%><input type=submit value=Go name=cari></font></td></tr></table></form>";
	return $txt;
}

/*function format_mede($angka,$digit=2){
	return "<div align=right>".number_format($angka,$digit)."</div>";	
}*/
function format_mede($angka,$digit=0,$xx="",$yy=""){
	if($angka < 0){
		$str_temp= "(".number_format((0-$angka),$digit).")";
	}else{
		$str_temp= number_format($angka,$digit);
	}
	return $str_temp;
}

function format_dk($angka,$digit=0,$xx="",$yy=""){
	if($angka <=0){
		$str_temp= number_format((0-$angka),$digit)." K";
	}else{
		$str_temp= number_format($angka,$digit). " D";
	}
	return $str_temp;
}

function combo_bulana($nama,$sel,$all=""){
	global $bulan;
	$txtout="<select name=$nama class=\"form2\">";
	if($all<>""){
		$txtout .= "<option value=-1>All</option>";
	}
	for ($i=1;$i<=12;$i++){
		if ($i==$sel){
			$tulis =" selected";
		}
		$txtout .= "<option value=$i $tulis>".$bulan[$i]."</option>";
		$tulis = "";
	}
	$txtout .= "</select>";
	return $txtout;
}

function combo_tanggala($nama,$sel,$awal,$akhir){
	$txtout="<select name=$nama class=\"form2\">";
	for ($i=$awal;$i<=$akhir;$i++){
		if ($i==$sel){
			$tulis =" selected";
		}
		$txtout .= "<option value=$i $tulis>".$i."</option>";
		$tulis = "";
	}
	$txtout .= "</select>";
	return $txtout;
}

function combo_bulan($nama,$sel,$all=""){
	global $bulan;
	$txtout="<select name=$nama style=\"background-color: #FFFFFF\" class=\"tombol\">";
	if($all<>""){
		$txtout .= "<option value=-1>All</option>";
	}
	for ($i=1;$i<=12;$i++){
		if ($i==$sel){
			$tulis =" selected";
		}
		$txtout .= "<option value=$i $tulis>".$bulan[$i]."</option>";
		$tulis = "";
	}
	$txtout .= "</select>";
	return $txtout;
}

function combo_tanggal($nama,$sel,$awal,$akhir){
	$txtout="<select name=$nama style=\"background-color: #FFFFFF\" class=\"tombol\">";
	for ($i=$awal;$i<=$akhir;$i++){
		if ($i==$sel){
			$tulis =" selected";
		}
		$txtout .= "<option value=$i $tulis>".$i."</option>";
		$tulis = "";
	}
	$txtout .= "</select>";
	return $txtout;
}

function ctr_array($arr){
	echo "<pre>";
	print_r($arr);
	echo "</pre>";
}

function dbresult($sql){
	global $conn;
	global $db;
	if(!isset($conn)){
                $conn = odbc_connect("Driver={PostgreSQL ODBC Driver(UNICODE)};Server=localhost;Database=$db[dbname]","$db[user]","$db[password]");
		//$conn = odbc_connect("$db[dbname]","$db[user]","$db[password]");
	}
	if(!$result = odbc_exec($conn, $sql)){
		echo "Proses ke database gagal";
		echo "<br>$sql<br>";
		odbc_errormsg($conn);	
	}
	//echo "<br>$sql<br>";
	return $result;
}

function dbresult_pg($sql){
	global $conn_pg;
	global $db_pg;
	if(!isset($conn_pg)){
		while(list($key,$isi)=each($db_pg)){
			$opt .= "$key=$isi ";
		}
		$conn_pg = pg_connect($opt);
	}	
	if(!$result = pg_exec($conn_pg, $sql)){
		echo "<br>$sql<br>";
		echo "Proses ke database gagal";
		pg_errormessage($conn_pg);	
	}

	//echo "<br>$sql<br>";
	return $result;
}

function var_kirim($inp_par,$ha_nama=""){
	if(is_array($inp_par)){
		while(list($nama,$nilai)=each($inp_par)){
			if(strpos(",$ha_nama,","$nama,")==0){
				$var_post.="&inp_par[$nama]=".rawurlencode($nilai)."";
#echo $nilai."<br>";
			}
		}
	}

#echo "<pre>";
#print_r($inp_par);
#echo "</pre>";

#	echo "$ha_nama,$var_post <br>";
	return $var_post;
}
function var_kirim2($inp_par,$ha_nama=""){
	if(is_array($inp_par)){
		while(list($nama,$nilai)=each($inp_par)){
			if(strpos(",$ha_nama,","$nama,")==0){
				$var_post.="&inp[$nama]=".rawurlencode($nilai)."";
#echo $nilai."<br>";
			}
		}
	}

#echo "<pre>";
#print_r($inp_par);
#echo "</pre>";

#	echo "$ha_nama,$var_post <br>";
	return $var_post;
}

function awal_akhir_transaksi($no_transaksi,$tahun,$combo_cari,$cari1,$cari2,$tambah_sql=""){
	global $cdivisi_kode;
        if($combo_cari=="no_transaksi"){
		//$tambah_ort=$cari2!=""?" and no_transaksi='$cari2'":"";
                $sql_tambahan.=$cari1!=""?" and (cast(no_transaksi as integer)='$no_transaksi' $tambah_ort)":"";
        }elseif($combo_cari=="no_bukti"){
		//$tambah_orb=$cari2!=""?" and key_lain like '%$cari2%'":"";
		//$tambah_orbb=$cari2!=""?" and no_bukti'%$cari2%'":"";
		$sql_tambahan.=$cari1!=""?" and  key_lain like '%$cari1%' $tambah_orb":"";
                //$sql_tambahan.=$cari!=""?" and (cast(substr(no_bukti,1,3) as integer)>='$cari1' $tambah_orbb)":"";
        }
	$sql="select min(debet_kredit_id) as awal,max(debet_kredit_id) as akhir,key_lain from tbl_debet_kredit where true and (data_divisi_kode='$cdivisi_kode' or data_divisi_kode like '$cdivisi_kode.%') and date_part('year',periode_posting)='$tahun' $sql_tambahan $tambah_sql group by key_lain";
	//echo	$sql."<br>";
	$res=dbresult($sql);
	//$r=odbc_fetch_array($res,0);
	//return array("awal"=>$r[key_lain][$r[awal]],"akhir"=>$r[key_lain][$r[akhir]]);
	while($r=odbc_fetch_array($res,0)){
		$key_lain=$r[key_lain];
		$arr_temp[$key_lain]["awal"]=$r[awal];
		$arr_temp[$key_lain]["akhir"]=$r[akhir];
        }
        return $arr_temp;
}

function cari_debet_kredit_id($tahun){
	global $cdivisi_kode;
	$sql="select max(debet_kredit_id) as debet_kredit_id from tbl_debet_kredit where true and (data_divisi_kode='$cdivisi_kode' or data_divisi_kode like '$cdivisi_kode.%') and tahun='$tahun'";
//	echo $sql."<br>";
	$rs=dbresult($sql);	
	while($r=odbc_fetch_array($rs)){
		$r[debet_kredit_id]=$r[debet_kredit_id]==""?0:$r[debet_kredit_id];
		return $r[debet_kredit_id]+1;
	}
}

function number_mede($angka,$digit=2){
	return number_format($angka,$digit);
}

function combo_jumlah_halaman($jml,$filter){
	global $awalan;
	//global $jml;
	$txt.="<select name=awalan onChange=\"javascript:loncat('mainFrame',this,0)\">";
	for ($i=1;$i<=$jml;$i++){
		if($awalan==($i-1)){
			$txt.="<option value=\"?awalan=".($i-1)."$filter\" selected>Hal $i</option>";
		}else{
			$txt.="<option value=\"?awalan=".($i-1)."$filter\">Hal $i</option>";
		}
	}
	$txt.="</select>";
	return $txt;
}

function definisi_halaman($sql,$var_tambahan=""){
	global $awalan;
	global $var_post;
	global $jumlah_per_hal,$mode;
	if($awalan==""){
		$awalan = 0;
		$next = $awalan + 1;
	}else{
		$awal_prev = $awalan - 1;
		$next=$awalan + 1;
	}
	$awalan_sql = $awalan * $jumlah_per_hal;
	$res=dbresult($sql);
	$jumlah=odbc_num_rows($res);
	$jml=ceil($jumlah/$jumlah_per_hal);
//	echo $jml."=".ceil."(".$jumlah."/".$jumlah_per_hal.")";
	$str_list.="<table width=30% border=0><tr><td>";
	if($jumlah > $jumlah_per_hal){
		if($awalan==0){	
			$str_list.="<font face=arial size=2 color=#527ACC>&nbsp;&nbsp;&nbsp;</font>";
			$str_list.=combo_jumlah_halaman($jml,"$var_post$var_tambahan");
			$str_list.="<a href=$link?awalan=$next$var_post$var_tambahan><img src=../gambar/tombol-next.gif border=0></a>";
		}else{
			$str_list.="<a href=$link?awalan=$awal_prev$filter$order_$var_post$var_tambahan><img src=../gambar/tombol-prev.gif border=0></a>";
			$str_list.=combo_jumlah_halaman($jml,"$filter$order_$var_post");
			if($awalan<($jml-1)){
				$str_list.="<a href=$link?awalan=$next$filter$order_$var_post$var_tambahan><img src=../gambar/tombol-next.gif border=0></a>";
			}else{
				$str_list.="<font face=arial size=2 color=#527ACC>&nbsp;</font>";
			}
		}
	}
	$str_list.="</td></tr></table>";
	$res=dbresult($sql." limit ".$jumlah_per_hal." offset ".$awalan_sql);
	return array("tabel_halaman"=>$str_list,"res_sql"=>$res);
}

function cari_nilai($sql){
	$res=dbresult($sql);
	$r=odbc_fetch_array($res);
	return $r[nilai];
}


function tabel_view($nm_table,$id,$link="/balifocus/tea_admin.php",$obj="",$bgjudul="ffffff",$warnatulisan="000000",$bgisi="ffffff",$width = "100%",$kondisi="t",$sqlcari="",$kreteria_tambahan="",$template="",$fld_jumlah_1="",$fld_jumlah_2="",$caption_1="",$caption_2=""){
	global $REQUEST_URI;
	global $mode,$nospk;
	global $permisi;
	global $obj;
	global $kode;
	global $cari,$src_divisi,$src_tahun;
	global $cusername;
	global $awalan;
	global $order,$sql_propinsi,$spl_prop;
	global $src_kata;
	global $src_jenis;
	global $subbidang,$propinsi;
	$jumlah_per_hal = 20;
	//echo $nm_table;
	if($awalan==""){
		$awalan = 0;
		$next = $awalan + 1;
	}else{
		$awal_prev = $awalan - 1;
		$next=$awalan + 1;
	}
	$awalan_sql = $awalan * $jumlah_per_hal;
	$bgheader  = "darkblue";
	$result=dbresult($nm_table);
	$result=dbresult($nm_table);
	$result_cari=dbresult($sqlcari);
	$jumlah = odbc_num_rows($result);
	if($order==""){
		$order = odbc_field_name($result_cari,1);
	}
	$result=dbresult($nm_table ." order by ".$order." limit ".$jumlah_per_hal." offset ".$awalan_sql);
	//cari_subjumlah
	$fnum= odbc_num_fields($result);
	$num = odbc_num_rows($result); 
	//echo $nm_table;
	$jml=ceil($jumlah/$jumlah_per_hal);
	$jmlakhir=$jml-1;
	$link_cari="&src_kata=$src_kata&src_jenis=$src_jenis&src_divisi=$src_divisi&src_tahun=$src_tahun&cari=$cari";
	if($jumlah > $jumlah_per_hal){
		if($awalan==0){	
			$kata2="<font face=arial size=2 color=blue><a href=$link?awalan=$next$link_cari><img src=../gambar/tombol-nex.gif alt=\"Halaman Berikutnya\" width=18 height=18 border=0></a> &nbsp;<a href=$link?awalan=$jmlakhir$link_cari><img src=../gambar/tombol-last.gif alt=\"Halaman Akhir\" width=18 height=18 border=0></a></font>";
		}else{
			$kata1="<a href=$link?awalan=0$link_cari><img src=../gambar/tombol-first.gif alt=\"Halaman Akhir\" width=18 height=18 border=0></a> &nbsp;<font face=arial size=2 color=blue><a href=$link?awalan=$awal_prev$link_cari><img src=../gambar/tombol-pret.gif alt=\"Halaman Sebelumnya\" width=18 height=18 border=0></a></font>";
			if($awalan<($jml-1)){
				$kata2="<font face=arial size=2 color=blue><a href=$link?awalan=$next$link_cari><img src=../gambar/tombol-nex.gif alt=\"Halaman Berikutnya\" width=18 height=18 border=0></a> &nbsp;<a href=$link?awalan=$jmlakhir$link_cari><img src=../gambar/tombol-last.gif alt=\"Halaman Akhir\" width=18 height=18 border=0></a></font>";
			}
		}
	}
	$txt = "<table width=$width border=0 align=center>";
	if($subbidang<>"" and $propinsi<>""){
		$tmbhlink="&subbidang=$subbidang";
		$tmbhlink1="&propinsi=$propinsi";
	}
	if($nospk<>""){
		$tmbhspk="&nospk=$nospk";
	}
//	if(isset($cusername)){
		/*
		$txt .= "<tr><td colspan=".($jml_colom+1)." bgcolor=#1A75BF><table width=100%><tr><td width=50%>";
		if($permisi["add"]=="izin"){
			$txt .= "<a href=\"$link?mode=add&obj=$obj$tmbhspk$tmbhlink$tmbhlink1&kode=$kode$kreteria_tambahan\"> <img src=../gambar/tombol-add.gif border=0></a>";
		}
		$txt .= "</td><td width=50% align=right>$kata1 $kata2</td></tr></table></td></tr>";
		*/
//	}
	$txt .= "<tr><td align=center bgcolor=#eeeeee><table width=$width border=0 cellpadding=1 cellspacing=1 bgcolor=#d0ebf6><tr bgcolor=$bgheader>";
	$txt .= "<td bgcolor=$bgjudul valign=top align=center width=30><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\"><b>NO</b></font></td>";
	for ($i=0; $i <= $fnum; $i++){
		if($kondisi=="t"){
			if($i <> $id){
				if($i<$fnum){
					$str_order="&order=".odbc_field_name($result_cari, $i);
				}
				$txt .= "<td bgcolor=$bgjudul valign=top align=center><a href=$link?$link_cari$str_order style='TEXT-DECORATION: none'><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\"><b>".odbc_field_name($result, $i)."</b></font></a></td>";
			}
		}else{
			$txt .= "<td bgcolor=$bgjudul valign=top align=center><a href=$link?order=".odbc_field_name($result_cari, $i)." style='TEXT-DECORATION: none'><font face=verdana size=2 color=white><b>"
				.odbc_field_name($result, $i)."</b></font></a></td>";
		}
	}
	$txt .= "</tr>";

	$txt .= "<tr bgcolor=#1A75BF><td valign=top align=center><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">1</font></td>";
	for ($i=0; $i <= $fnum; $i++){
		if($kondisi=="t"){
			if($i <> $id){
				if($i<$fnum-1){
#	$str_order="&order=".odbc_field_name($result_cari, $i);
				}
				$txt .= "<td valign=top align=center><font color=\"#FFFFFF\" size=\"1\" face=\"Verdana, Arial, Helvetica, sans-serif\">".(1+$i)."</font></td>";
			}
		}else{
			$txt .= "<td bgcolor=$bgjudul valign=top align=center><font face=verdana size=2 color=white>".(1+$i)."</font></td>";
		}
	}
	$txt .= "</tr>";
	$jml = odbc_num_rows($result);
	$jml_colom = odbc_num_fields($result);
	$i=0;
	while(odbc_fetch_row($result) ) {  
		//for ($i=0; $i<$jml; $i++){
		if($warna_isi=="#E8EFFF"){
			$warna_isi="#ffffff";
		}else{
			$warna_isi="#E8EFFF";
		}
		$txt.= "<tr bgcolor=$warna_isi>";
		$txt .= "<td valign=top align=center><font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">".($awalan_sql+$i+1)."</font></td>";
		for ($j=1; $j<=odbc_num_fields($result); $j++){
			$txt .= "<td valign=top><font size=1 face=\"Verdana, Arial, Helvetica, sans-serif\">".odbc_result($result,$j)."</font></td>";
		}
		$i=$i+1;
		$txt .="</tr>";
	}
	if($subbidang<>"" and $propinsi<>""){
		$tmbhlink="&subbidang=$subbidang";
		$tmbhlink1="&propinsi=$propinsi";
	}
	if($nospk<>""){
		$tmbhspk="&nospk=$nospk";
	}
//	if(isset($cusername)){
		$txt .= "<tr><td colspan=".($jml_colom+1)." bgcolor=#1A75BF><table width=100%><tr><td width=50%>";
		if($permisi["add"]=="izin"){
			$txt .= "<a href=\"$link?mode=add&obj=$obj$tmbhspk$tmbhlink$tmbhlink1&kode=$kode$kreteria_tambahan\"> <img src=../gambar/tombol-add.gif border=0></a>";
		}
		$txt .= "</td><td width=50% align=right>$kata1 $kata2</td></tr></table></td></tr>";
//	}
	$txt .= "</table></td></tr></table><div align=center></div>";
	return $txt;
	}

	function combo_ya_tidak($nama,$nilai){
		$txtout.="<select name=$nama>";	
		if($nilai=="t"){
			$txtout.="<option value=t selected>Ya</option>";
			$txtout.="<option value=f>Tidak</option>";
		}else{
			$txtout.="<option value=t>Ya</option>";
			$txtout.="<option value=f selected>Tidak</option>";
		}
		$txtout.="</select>";
		return $txtout;
	}

	function baca_ya_tidak($nilai){
		if($nilai=="t"){
			$txtout.="Ya";
		}else{
			$txtout.="Tidak";
		}
		return $txtout;
	}

	function combo_city($nmtable,$nilaifld,$muncul,$nama,$option="All",$nilai=""){
		$txt = "<select name=$nama size=1>";
		$result=dbresult("select * from $nmtable order by $muncul");
		$jml = odbc_num_rows($result);
		$txt .="<option value=-1>$option</option>";
		for ($i=0;$i<$jml;$i++){
			$r = odbc_fetch_array($result,$i);
			if(trim($r[$nilaifld])==trim($nilai)){
				$txt .= "<option value=$r[$nilaifld] selected>$r[$muncul]</option>";
			}else{
				$txt .= "<option value=$r[$nilaifld]>$r[$muncul]</option>";
			}
		}
		$txt .= "</select>";
		return $txt;
	}

	function combo_event($nmtable,$nilaifld,$muncul,$nama,$option="All",$nilai="",$cek_sql=""){
		$txt = "<select name=$nama size=1 style=\"background-color: #FFFFDD\" onchange='pindah()'>";
		if($cek_sql == ""){
			$result=dbresult("select * from $nmtable order by $muncul");
		}else{
			$result=dbresult("$nmtable");
		}
		$jml = odbc_num_rows($result);
		if($option=="All"){
			$txt .="<option value=-1>$option</option>";
		}
		for ($i=0;$i<$jml;$i++){
			$r = odbc_fetch_array($result,$i);
			if(trim($r[$nilaifld])==trim($nilai)){
				$txt .= "<option value='$r[$nilaifld]' selected>$r[$muncul]</option>";
			}else{
				$txt .= "<option value='$r[$nilaifld]'>$r[$muncul]</option>";
			}
		}
		$txt .= "</select>";
		return $txt;
	}

	function combo($nmtable,$nilaifld,$muncul,$nama,$option="",$nilai="",$cek_sql="",$java=""){
		$txt = "<select name=$nama size=1 style=\"background-color: #FFFFFF\" $java class=tombol>";
		if($cek_sql == ""){
			$result=dbresult("select $nilaifld,$muncul from $nmtable order by $nilaifld");

		}else{
			$result=dbresult("$nmtable");
		}
		$jml = odbc_num_rows($result);
		if($option!=""){
			$txt .="<option value=-1>$option</option>";
		}
		//echo odbc_num_fields($result);
		while (odbc_fetch_row($result)){
			$cmb_nilai=odbc_result($result,1);
			$cmb_muncul=odbc_result($result,2);
			if(trim($cmb_nilai)==trim($nilai)){
				$txt .= "<option value='".$cmb_nilai."' selected>".$cmb_muncul."</option>";
			}else{
				$txt .= "<option value='".$cmb_nilai."'>".$cmb_muncul."</option>";
			}
		}
		$txt .= "</select>";
		return $txt;
	}

	function combo_knowledge($nmtable,$nilaifld,$muncul,$nama,$option="All",$nilai="",$cek_sql=""){
		$txt = "<select name=$nama size=1 style=\"background-color: #FFFFDD\">";
		if($cek_sql == ""){
			$result=dbresult("select * from $nmtable order by $muncul");
		}else{
			$result=dbresult("$nmtable");
		}
		$jml = odbc_num_rows($result);
		if($option=="All"){
			$txt .="<option value=-1>$option</option>";
		}
		for ($i=0;$i<$jml;$i++){
			$r = odbc_fetch_array($result,$i);
			if(trim($r[$nilaifld])==trim($nilai)){
				$txt .= "<option value='$r[$nilaifld]' selected>$r[$muncul]</option>";
			}else{
				$txt .= "<option value='$r[$nilaifld]'>$r[$muncul]</option>";
			}
		}
		$txt .= "</select>";
		return $txt;
	}


	function arr_minggu(){
		$arr= array("Sun"=>0,"Mon"=>1,"Tue"=>2,"Wed"=>3,"Thu"=>4,"Fri"=>5,"Sat"=>6);
		return $arr;
	}

	function combo_array($nama,$arr_nilai,$sel){
		$txtout.="<select name=$nama style=\"background-color: #FFFFFF\" class=\"tombol\">";	
		while(list($key,$nilai)=each($arr_nilai)){
			if($nilai==$sel){
				$txtout.="<option value='$nilai' selected>$nilai</option>";	
			}else{
				$txtout.="<option value='$nilai'>$nilai</option>";	
			}
		}
		$txtout.="</select>";	
		return $txtout;
	}

	function combo_array2($nama,$arr_nilai,$sel,$disabled="f",$java="",$option="",$namaid=""){
		if($disabled=="t"){$dis="disabled";}
		if($namaid==""){$namaid=$nama;}
		$txtout.="<select name=\"$nama\" style=\"background-color: #FFFFFF\" class=tombol $dis $java id=\"$namaid\">\n";
		if($option==" "){
			$txtout .="<option value=''>$option</option>";
		}
		while(list($key,$nilai)=each($arr_nilai)){
			if(trim($key)===trim($sel)){
				$txtout.="<option value='$key' selected>$nilai</option>\n";	
			}else{
				$txtout.="<option value='$key'>$nilai</option>\n";
			}
		}
		$txtout.="</select>\n";
		return $txtout;
	}

	function combo_array_new($nama,$arr_nilai,$sel){
		$txtout.="<select name=$nama style=\"background-color: #FFFFFF\" class=\"tombol\">";	
		while(list($key,$nilai)=each($arr_nilai)){
			if($key==$sel){
				$txtout.="<option value='$key' selected>$nilai</option>";	
			}else{
				$txtout.="<option value='$key'>$nilai</option>";	
			}
		}
		$txtout.="</select>";	
		return $txtout;
	}
	function combo_kelamin($nama,$nilai){
		$txtout.="<select name=$nama>";	
		if(trim($nilai)=="pria"){
			$txtout.="<option value=pria selected>Pria</option>";
			$txtout.="<option value=wanita>Wanita</option>";
		}else{
			$txtout.="<option value=pria>Pria</option>";
			$txtout.="<option value=wanita selected>Wanita</option>";
		}
		$txtout.="</select>";
		return $txtout;
	}
	function check_extension($curdir_upload){
		$str_izin=".jpg,.gif,.xls,.JPG,.JPEG,.jpeg,.GIF";	
		$arr_izin=split(",",$str_izin);
		while(list($key,$nilai)=each($arr_izin)){
			if(strpos($curdir_upload,$nilai)>0){
				return true;
			}	
		}
	}


	function fileupload_($userfile,$userfile_name,$curdir_upload){
#global $curdir_gambar;
#global $userfile_name;
		if($userfile!=""){
			if(!is_dir("$curdir_upload/")){
				mkdir("$curdir_upload",0700);
			}
			if(check_extension($userfile_name)){
				if(!copy($userfile,"$curdir_upload/$userfile_name")){
					echo "error cuk $curdir_upload";
				}
			}else{
				echo "Jenis File Tidak Diterima $userfile_name";
			}
#if (!copy($userfile, "$curdir_gambar$userfile_name")) { 
#print ("failed to copy $userfile...<br>\n"); 
#}else{ 
#echo "berhasil copy $userfile ke $curdir_gambar$userfile_name<br>";
#echo "$curdir_gambar$userfile_name";
#}
		}
	}

	function fileupload_isa($userfile,$userfile_name,$curdir_upload){
		global $cnospk_pilih;
		global $bulan_,$var_thn,$inp;
#global $curdir_gambar;
#global $userfile_name;
		if($userfile!=""){
			if(!is_dir("$curdir_upload/")){
				mkdir("$curdir_upload",0700);
			}
			if(check_extension($userfile_name)){
				if(!copy($userfile,"$curdir_upload/".$cnospk_pilih."_".$inp[arp]."_".$bulan_."_".$var_thn.".xls")){
					echo "error cuk $curdir_upload";
				}
			}else{
				echo "Jenis File Tidak Diterima $userfile_name";
			}
#if (!copy($userfile, "$curdir_gambar$userfile_name")) { 
#print ("failed to copy $userfile...<br>\n"); 
#}else{ 
#echo "berhasil copy $userfile ke $curdir_gambar$userfile_name<br>";
#echo "$curdir_gambar$userfile_name";
#}
		}
	}



	function fileupload_bambong($userfile,$userfile_name,$curdir_upload){
		//global $curdir_upload;
		//global $userfile_name;
		if($userfile!=""){
			if(!is_dir("$curdir_upload/")){
				mkdir("$curdir_upload",0700);
			}

#if(!copy($userfile,"$curdir_upload/$userfile_name")){
#	echo "error cuk $curdir_upload";
#}
			if (!copy($userfile, "$curdir_upload$userfile_name")) { 
				print ("failed to copy $userfile...<br>\n"); 
			}else{ 
# echo "berhasil copy $userfile ke $curdir_gambar$userfile_name<br>";
# echo "$curdir_gambar$userfile_name";
			}
		}
	}

	function list_voucher($sql,$sqlcari,$gambar='gambar/judul-user.gif',$status='f',$muncul_divisi="",$tambahan_sql="",$template="",$fld_jumlah_1="",$fld_jumlah_2="",$caption_1="",$caption_2="",$muncul_tahun="",$kriteria_tambahan=""){
		global $src_kata;
		global $src_jenis,$nospk;
		global $cari;
		if ($status == ''){
			$status='f';	
		}
		//echo kepala($gambar);
		echo bar_cari($sql,"",$muncul_divisi,$muncul_tahun);	
		if($cari<>""){
			if ($src_kata <> ""){
				$result=dbresult($sqlcari);
				$fnum= odbc_num_fields($result);
				if ($src_jenis == -1){
					for ($i=1; $i<=$fnum; $i++){
						$tambahan .= "lower(".odbc_field_name($result, $i).") like lower('%$src_kata%') or ";
					}
					$tambahan = substr($tambahan,0,strlen($tambahan) - 3);
				}else{
					$j = $src_jenis;
					$tambahan = "lower(".odbc_field_name($result, $j) .") like lower(('%$src_kata%'))";
				}
				if(strpos("$sql","where")>0){
					$sql = $sql ." and (". $tambahan .") $tambahan_sql";
				}else{
					$sql = $sql ." where ". $tambahan. $tambahan_sql;
				}
			}else{
				if(trim($tambahan_sql)<>""){
					if(strpos("$sql","where")>0){
						$sql = $sql ." and (true $tambahan_sql)";
					}else{
						$sql = $sql ." where true ". $tambahan_sql;
					}
				}
			}
		}
		$txtout.= tabel_view($sql,0,'','','#1A75BF','white','white',"100%","t",$sqlcari,$kriteria_tambahan,$template,$fld_jumlah_1,$fld_jumlah_2,$caption_1,$caption_2);
		return $txtout;
	}

	function kepala($gambar){
		$txt_out.="
			<table width=\"98%\" height=\"31\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
			<tr> 
			<td height=\"40\" valign=\"bottom\"><img src=\"$gambar\"></td>
			</tr>
			<tr> 
			<td height=\"1\" bgcolor=\"#6699ff\"><img src=\"gambar/0.gif\" width=\"1\" height=\"1\"></td>
			</tr>
			</table>";
		return $txt_out;
	}
	function tabel_array($sql){
		$res=dbresult($sql);
		$jml=odbc_num_rows($res);
		for($i=0;$i<$jml;$i++){
			//$r=odbc_fetch_row($res,$i);
			$r=odbc_fetch_array($res);
			//$arr_x["$r[0]"]=$r[1];
			$arr_x["$r[user_id]"]=$r[level_access];
		}
		return $arr_x;
	}

	function set_kode(){
		global $cusername;
		$qr="select divisi_kode from tbl_user where user_name='$cusername'";
		$rsl=dbresult($qr);
		$r=odbc_fetch_array($rsl);
		$kd=trim($r[divisi_kode]);
		$qry="select count(p_dini_kode) as \"jml\" from tbl_pasar_dini where p_dini_kode like '%$kd%'";
		$result=dbresult($qry);
		$k=odbc_fetch_array($result);
		$angka=$k[jml]+1;
		$kata=strlen($angka);
		$kt=$kd;
		for($i=1;$i<=4-$kata;$i++){
			$kt=$kt."0";
		}
		$kode_user=$kt."".$angka;
		return $kode_user;
	}

	function hapus_div($var_str){
		$tmp_var=trim(str_replace(",","",$var_str));
		$tmp_var=trim(str_replace("<div align=right>","",$tmp_var));
		$tmp_var=trim(str_replace("</div>","",$tmp_var));
		$tmp_var=intval($tmp_var);
		return $tmp_var;
	}

	function generate_rule($nama_rule,$nm_obj,$pesan_rule="",$rg_awal="0",$rg_akhir="0"){
		global $str_aturan;
		switch($nama_rule){
                    case "is_isi":$str_aturan.="if (document.all['$nm_obj'].value==''){alert('".$pesan_rule."'),document.all['$nm_obj'].focus(),valid=false;}\n";break;
			//case "is_isi":$str_aturan.="t10_checkisi(document.all['$nm_obj'],\"$pesan_rule\");\n";break;
			case "is_email":$str_aturan.="t10_checkmail(document.all['$nm_obj'],\"$pesan_rule\");\n";break;
			case "is_date":$str_aturan.="t10_checkvaliddate(document.all['$nm_obj[0]'],document.all['$nm_obj[1]'],document.all['$nm_obj[2]']);\n";break;
			case "is_num":$str_aturan.="t10_checknum(document.all['$nm_obj'],\"$pesan_rule\");\n";
			break;
			case "is_range":$str_aturan.="t10_checkrange(document.all['$nm_obj'],\"$pesan_rule\",$rg_awal,$rg_akhir);\n";
			break;
		}

	}

	function generate_validasi(){
		global $str_aturan;
		$txtout.='
			<SCRIPT language=javascript src=fungsi_validasi.js></SCRIPT>
			<SCRIPT language=javascript>
			var valid;
		function validasi(var_nama_form) {
			var nm_form=var_nama_form;
                        valid = true;
			//alert("test");
			'.$str_aturan.'
				if (valid){
					return true
				}else{
					return false
				}
		}

		</SCRIPT>';
		return $txtout;
	}

function data2array($sql,$nama_file,$nama_array="arr_x"){
	$res=dbresult($sql);
	if(!$tulisfile=fopen($nama_file,'w+')){
		print("Buka File $nama_file Gagal");
		$hasil=false;
	}else{
		$isi_file="var $nama_array=new Array(); \n";
		while($r=odbc_fetch_array($res)){
			$kunci=str_replace("'","",$r[account_kode]);
			$isi=str_replace("'","",$r[account_nama]);
			$isi_file.=$nama_array."['$kunci']='$isi'; \n";
		}
	}
	if(!fwrite($tulisfile,$isi_file)){
		print("Penulisan File $nama_file Gagal");
		$hasil=false;
	}else{
		fclose($tulisfile);
	}
	return $hasil;
}

function arr_nama($variabel1,$variabel2,$variabel3,$kondisi=""){
	global $cdivisi_account;
	global $tanda_account,$tanda_lb;
	$kondisine=$kondisi==""?"":"where $kondisi";
	$sql="select $variabel1,$variabel2 from $variabel3 $kondisine order by $variabel1 ";

	$res=dbresult($sql);//echo $sql;
	//echo $sql."<br>";
	while($r=odbc_fetch_array($res)){

		$acc=$r[$variabel1];
		$arr_temp[$acc]["nama"]=$r[$variabel2];
	}
	/*
	   echo "<pre>";
	   print_r($arr_temp);
	   echo "</pre>";
	 */
	return $arr_temp;
}

function e_getTotalDay($tahun,$bulan,$hari){
    if ($bulan==2){
        if ($tahun%4==0 && $hari>29){
            $hari = 29;
        }else if($tahun%4!=0 && $hari>28){
            $hari = 28;
        }
    }else if(($bulan==4 || $bulan==6 || $bulan==9 || $bulan==11) && $hari>30){
        $hari = 30;
    }
    return $hari;
}

function e_getIpAddr(){
    if (!empty($_SERVER['HTTP_CLIENT_IP'])){ // check ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ // check ip is pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else{
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

function e_getDateNow(){
    return date("Y-m-d");
}

function e_getTimeNow(){
    return date("H:i:s");
}

function e_getDMYOnly($no,$control){
    if (strtolower($control)=='tahun'){
        $x='Y';
    }
    if(strtolower($control)=='bulan'){
        $x='n';
    }
    if (strtolower($control)=='tanggal'){
        $x='j';
    }
    $tanggal = date("$x");
    //$tanggalhsl = $no.$tanggal;
    return $tanggal;
}


?>
